calendarize

1.1.1 · active · verified Sun Apr 19

calendarize is a minimalist (202B) JavaScript utility designed to generate structured calendar views for a given month. Currently at version 1.1.1, it provides an array of arrays representing weeks, where each inner array contains 7 numbers corresponding to days of the month, with `0` indicating days outside the current month. The library is highly flexible, providing no date labels or internationalization (i18n) directly, which allows developers complete control over localization and rendering. It ships as ES Module, CommonJS, and UMD, making it suitable for various environments. Its main differentiator is its tiny footprint and unopinionated output, focusing solely on the grid structure rather than presentation, and it has a steady, albeit slow, release cadence driven by community contributions for minor enhancements.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates generating a calendar view for a given date, including how to specify a different start day for the week using the `offset` parameter.

import calendarize from 'calendarize';

// Example 1: Calendar view for a specific date instance
// Week = [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
const dateInstanceView = calendarize(new Date('2024-07-20'));
console.log('July 2024 (Sunday start):', dateInstanceView);
/*
Output:
[
  [ 0,  1,  2,  3,  4,  5,  6],
  [ 7,  8,  9, 10, 11, 12, 13],
  [14, 15, 16, 17, 18, 19, 20],
  [21, 22, 23, 24, 25, 26, 27],
  [28, 29, 30, 31,  0,  0,  0]
]
*/

// Example 2: Calendar view for a date string with Monday as the start of the week
// Week = [Mon, Tue, Wed, Thu, Fri, Sat, Sun]
const mondayStartView = calendarize('Aug 01, 2024', 1);
console.log('August 2024 (Monday start):', mondayStartView);
/*
Output:
[
  [ 0,  0,  0,  1,  2,  3,  4],
  [ 5,  6,  7,  8,  9, 10, 11],
  [12, 13, 14, 15, 16, 17, 18],
  [19, 20, 21, 22, 23, 24, 25],
  [26, 27, 28, 29, 30, 31,  0]
]
*/

view raw JSON →