mnth is a lightweight, framework-agnostic utility library designed to simplify the generation of calendar-style month data. Its primary function, `getCalendarMonth`, takes a `Date` object and an optional configuration (e.g., `firstDayOfWeek`) to return a 2D array of `Date` objects, representing all days visible in a given month's calendar view, including leading and trailing days from adjacent months. Currently at version 2.0.0, the package provides a focused solution for UI components like datepickers and full calendars, distinguishing itself by providing raw `Date` objects for maximum flexibility rather than pre-formatted strings or complex component structures. It ships with TypeScript types, promoting strong type checking and improved developer experience. The library is part of the `nextools/metarepo` monorepo.
npm install mnthVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `getCalendarMonth` to generate a 2D array of `Date` objects for a given month, showing both default and custom `firstDayOfWeek` options. It then formats and logs the day numbers for each week.
Always refer to the documentation for the `firstDayOfWeek` option: `0` for Sunday, `1` for Monday (default), `6` for Saturday.
If immutability is crucial, clone `Date` objects from the `mnth` output before performing modifications (e.g., `new Date(day.getTime())`).
For consistent behavior, especially in applications serving users across different timezones, consider creating input `Date` objects in UTC (e.g., `new Date('YYYY-MM-DDTHH:MM:SSZ')`) and handle display-side timezone conversions explicitly, or use dedicated internationalization APIs.Ensure your project is configured for ES Modules (e.g., `"type": "module"` in `package.json` for Node.js) and use `import { getCalendarMonth } from 'mnth';`. If you must use CommonJS, you might need a bundler like Webpack or Rollup to transpile ESM to CJS, or explore dynamic `import()`.Validate your input `Date` object before passing it to `getCalendarMonth`. Check if `isNaN(date.getTime())` is true, which indicates an invalid Date. Ensure date strings are in a consistent, parsable format (e.g., ISO 8601).
No dependency data recorded yet.