A Node.js-based library and CLI tool to calculate monthly, six-month, and yearly salaries based on hourly rate, working hours per day, and public holidays.
- Fetches public holidays dynamically using the Nager.Date API.
- Calculates working days in a month, excluding weekends and holidays.
- Computes monthly, first six-month, and yearly salaries.
- Simple CLI interface and reusable library functions.
git clone https://github.com/briandiaz/monthly-salary-calculator.git
cd monthly-salary-calculator
npm install
npm run build
- Build the project:
npm run build
- Start the CLI:
npm start
The CLI will guide you through entering your hourly rate, working hours per day, and country code to fetch holidays. It will then display a breakdown of monthly salaries.
You can use the functions provided by the library programmatically in your project.
const {
fetchHolidays,
} = require("monthly-salary-calculator/dist/lib/holidays");
const {
calculateMonthlySalaries,
} = require("monthly-salary-calculator/dist/lib/calculate");
(async () => {
const holidays = await fetchHolidays("US", 2025); // Replace "US" with your country code
const results = calculateMonthlySalaries(2025, 25, 8, holidays); // Hourly rate: $25, 8 hours/day
console.table(results.monthlySalaries);
console.log("First 6-month salary:", results.sixMonthSalary);
console.log("Yearly salary:", results.yearlySalary);
})();
monthly-salary-calculator/
├── src/
│ ├── cli.ts # CLI implementation
│ ├── lib/
│ │ ├── holidays.ts # Holiday fetching logic
│ │ ├── calculate.ts # Salary calculation logic
│ │ └── prompts.ts # CLI prompts
├── dist/ # Compiled JavaScript files
├── scripts/ # Utility scripts (e.g., post-build fixes)
├── .gitignore # Git ignore rules
├── package.json # Project metadata and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # Documentation
The project uses TypeScript with the following settings:
target
: ES2020module
: CommonJSstrict
: Enabled for robust type-checking
Run the TypeScript compiler in watch mode:
npm run dev
Compile the TypeScript files:
npm run build
Fetches an array of public holidays for the specified country and year.
-
Parameters:
countryCode
: ISO 3166-1 alpha-2 country code (e.g., "US" for United States).year
: Year to fetch holidays for (e.g.,2025
).
-
Returns:
Promise<string[]>
– Array of holiday dates as strings.
calculateMonthlySalaries(year: number, hourlyRate: number, hoursPerDay: number, holidays: string[]): { monthlySalaries: Array<{ month: string, workingDays: number, monthlySalary: number }>, yearlySalary: number, sixMonthSalary: number }
Calculates monthly, first six-month, and yearly salaries.
- Parameters:
year
: Year to calculate salaries for (e.g.,2025
).hourlyRate
: Hourly rate in your currency.hoursPerDay
: Number of working hours per day.holidays
: Array of holidays to exclude from working days.
- Nager.Date API for providing public holiday data.
- Node.js and TypeScript for powering this project.
Author: Brian Díaz
Feel free to reach out for collaboration or questions!
Contributions are welcome! Feel free to fork this repository and submit a pull request with improvements.