A simple and light weight JavaScript calendar generator.
Install with npm:
$ npm install --save @skolacode/calendar-js
Install with yarn:
$ yarn add @skolacode/calendar-js
import { getCalendar } from '@skolacode/calendar-js'
const july2022Calendar = getCalendar(6, 2022)
console.log(july2022Calendar)
/**
response:
{
calendar: [
[
{
date: 2022-06-25T16:00:00.000Z,
day: 26,
weekday: 'Sunday',
isCurrentMonth: false
},
...
],
[...],
....
month: 6,
year: 2022,
next: { month: 7, year: 2022 },
previous: { month: 5, year: 2022 }
}
*/
getCalendar(month: number, year: number, startingDay?: number): ICalendar
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
month | Number | Yes | - | The month of the calendar (0 to 11). 0 = January, 1 = February |
year | Number | Yes | - | The year of the calendar |
startingDay | Number | No | 1 | The starting day of the week (0 to 6). 0 = Sunday, 1 = Monday |
daysInMonth(month: number, year: number): number
Return the total number of days in a month.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
month | Number | Yes | - | The month of the calendar (0 to 11). 0 = January, 1 = February |
year | Number | Yes | - | The year of the calendar |
type TWeekdays = 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
type TDate = {
date: Date,
day: number,
isCurrentMonth: boolean,
weekday: TWeekdays,
};
interface ICalendar {
calendar: TDate[][];
month: number;
year: number;
next: {
month: number,
year: number,
};
previous: {
month: number,
year: number,
};
}
Pull Request:
- Fork this repo
- Create new branch for bug fixes or new feature
- Create/update test files
- Make sure build run successfully
Contribution are always open. Report issues or feature requests on GitHub Issues