calendar-grid

Simple calendar grid for JavaScript. If you're looking for PHP version of library, see here: https://github.com/dimsog/php-calendar-grid

Usage no npm install needed!

<script type="module">
  import calendarGrid from 'https://cdn.skypack.dev/calendar-grid';
</script>

README

Calendar grid

Simple calendar grid for JavaScript. If you're looking for PHP version of library, see here: https://github.com/dimsog/php-calendar-grid

Warning

This is NOT UI library!

Features

  • VanillaJS framework
  • Zero dependencies
  • Small size

Install

npm i dimsog/calendar-grid

Code examples

import CalendarGrid from 'calendar-grid';

let calendar = new CalendarGrid();
calendar.get(); // array of items
Advanced example:
import CalendarGrid from 'calendar-grid';

let calendar = new CalendarGrid({
    monday_first: true,
    year: 2019,
    month: 5, // 0..11
    days: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    current_date: new Date(2019, 5, 20) // custom current day
});

calendar.get(); // array of items

One array item:

  • date: String or Date instance (if you use get() method)
  • type: Integer. -1 - prev month, 0 - current month, 1 - next month
  • year: Integer
  • month: Integer. 0 - January, 11 - December.
  • human_month: Integer, 1 - January, 12 - December
  • day: Integer
  • current_day: Bool
  • number: Integer. Day of the week
  • name: String. Name day of the week

calendar.toJSON():

You can use toJSON() method if you want to receive JSON string.

[
{},
    {
        "date":"2019-05-28",
        "type":-1,
        "year":2019,
        "month":4,
        "human_month": 5,
        "day":28,
        "current_day":false,
        "number":2,
        "name":"Tue"
    },
{}
]

Make monday first day:

calendar.mondayIsFirstDay();

Change current day:

calendar.setCurrentDate(new Date(2019, 5, 20));