{"library":"mnth","title":"mnth: Calendar Month Generator","description":"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.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install mnth"],"cli":null},"imports":["import { getCalendarMonth } from 'mnth';","import type { Options } from 'mnth';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { getCalendarMonth } from 'mnth';\n\n// Get the calendar month for April 2018, with default options (Monday as first day of week)\nconst date = new Date('2018-04-01T12:00:00.000Z'); // Using UTC to avoid local timezone issues on initialization\nconst calendarMonth = getCalendarMonth(date);\n\nconsole.log('Calendar for April 2018 (default options):');\ncalendarMonth.forEach(week => {\n  console.log(week.map(day => day.toLocaleDateString('en-US', { day: '2-digit' })).join(', '));\n});\n\n// Example with custom options: Sunday as the first day of the week\nconst sundayFirstCalendar = getCalendarMonth(date, { firstDayOfWeek: 0 });\n\nconsole.log('\\nCalendar for April 2018 (Sunday as first day):');\nsundayFirstCalendar.forEach(week => {\n  console.log(week.map(day => day.toLocaleDateString('en-US', { day: '2-digit' })).join(', '));\n});\n\n/* Expected output structure (values depend on exact date/timezone):\nCalendar for April 2018 (default options):\n26, 27, 28, 29, 30, 31, 01\n02, 03, 04, 05, 06, 07, 08\n09, 10, 11, 12, 13, 14, 15\n16, 17, 18, 19, 20, 21, 22\n23, 24, 25, 26, 27, 28, 29\n30, 01, 02, 03, 04, 05, 06\n\nCalendar for April 2018 (Sunday as first day):\n25, 26, 27, 28, 29, 30, 31\n01, 02, 03, 04, 05, 06, 07\n08, 09, 10, 11, 12, 13, 14\n15, 16, 17, 18, 19, 20, 21\n22, 23, 24, 25, 26, 27, 28\n29, 30, 01, 02, 03, 04, 05\n*/","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}