@skolacode/calendar-js

Simple JavaScript calendar generator
197,773 5
Install
npm install @skolacode/calendar-js
Latest Version:1.0.2
License:ISC
Last Updated:Jan 18, 2023
Links: GitHub  ·  npm
Maintainer: burhan3759

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, options?: IOptions): 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
options.startingDay TStartingDay No 1 The starting day of the week (0 to 6). 0 = Sunday, 1 = Monday
options.extraWeek Boolean No true Calendar rows are fixed to 6 regardless of all the 6th week consists of days for next month

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

export type TStartingDay = 0 | 'SUNDAY' | 'Sunday' | 'sunday' | 1 | 'MONDAY' | 'Monday' | 'monday' | 2 | 'TUESDAY' | 'Tuesday' | 'tuesday' | 3 | 'WEDNESDAY' | 'Wednesday' | 'wednesday' | 4 | 'THURSDAY' | 'Thursday' | 'thursday' | 5 | 'FRIDAY' | 'Friday' | 'friday' | 6 | 'SATURDAY' | 'Saturday' | 'saturday';

export interface IOptions {
  startingDay?: TStartingDay | number;
  extraWeek?: boolean;
}

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

Related Packages

dates-generator

A simple javascipt dates generator functions

33,035 6
world-trigger

A small, easy, blazingly fast and scalable state-management solution for react.

1,321 0
schema-mocker

A powerful schema-based faker plugin for generating random data in TypeScript an...

692
vue-md-date-picker

A vue date picker component inspired by material design

4,331 55
@symbiote-native/localization

expo-localization wrapped for SymbioteNative — one framework-agnostic core, buil...

1,830 72

Version History

Version Released License
1.0.2 ISC
1.0.1 ISC
1.0.0 ISC