Skip to content

mereka-ta/calendar-js

 
 

Repository files navigation

CalendarJS NPM link

A simple and light weight JavaScript calendar generator.

Installation

Install with npm:

$ npm install --save @skolacode/calendar-js

Install with yarn:

$ yarn add @skolacode/calendar-js

Usage

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 }
}
*/

Methods

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

Types

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,
  };
}

Contributing

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%