Registry / web-framework / calendar-utils

calendar-utils

JSON →
library1.0.1jsnpmunverified

calendar-utils provides a set of utility functions designed to generate calendar views, abstracting away the complex date calculations required for displaying events across different time spans. It is currently at version 0.12.5, indicating a pre-1.0 release stage where API stability might be less guaranteed and breaking changes between minor versions are possible. The library is date library-agnostic, supporting popular options like `date-fns`, `luxon`, and `moment` through peer dependencies, allowing developers to choose their preferred date manipulation library. Its primary differentiator is its focus purely on view generation logic, making it a flexible backend for any calendar UI component, rather than a full-fledged UI solution itself. It ships with full TypeScript types, enhancing developer experience and type safety.

npm install calendar-utils
INSTALL
IMPORT
SIG · CALENDAR-UTILS
C
calendar-utils
web-frameworkjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getCalendarMonthView
import { getCalendarMonthView } from 'calendar-utils';
const { getCalendarMonthView } = require('calendar-utils');
calendar-utils is primarily designed for ESM usage. While CommonJS might work via transpilation, direct require is not the idiomatic way.
getCalendarWeekView
import { getCalendarWeekView } from 'calendar-utils';
import getCalendarWeekView from 'calendar-utils';
All primary view generation functions are named exports; there is no default export.
getCalendarDayView
import { getCalendarDayView, getWeekViewHeader } from 'calendar-utils';
import * as calendarUtils from 'calendar-utils';
It's best practice to import only the specific functions you need to optimize bundle size.

This quickstart demonstrates how to generate a calendar month view using `getCalendarMonthView` with `date-fns` for date manipulation.

import { getCalendarMonthView } from 'calendar-utils'; import { startOfMonth, endOfMonth, eachDayOfInterval, format, addMonths } from 'date-fns'; interface CalendarDay { date: Date; isToday: boolean; isWeekend: boolean; events: string[]; } const currentDate = new Date(); const monthStart = startOfMonth(currentDate); const monthEnd = endOfMonth(currentDate); const calendarMonthView = getCalendarMonthView({ date: currentDate, events: [], // Your events array, e.g., [{ start: new Date(), end: new Date(), title: 'Meeting' }] weekStartsOn: 0, // Sunday excluded: [], // e.g., [6] for Saturday viewStart: monthStart, viewEnd: monthEnd, hourSegments: 2, // Not directly used by month view, but part of config dayStartHour: 0, dayEndHour: 23, weekendDays: [0, 6] }); console.log(`Month View for ${format(currentDate, 'MMMM yyyy')}:`); calendarMonthView.days.forEach(day => { console.log(` ${format(day.date, 'yyyy-MM-dd')} (isCurrentMonth: ${day.inMonth}): ${day.events.length} events`); }); // Example of getting a day outside the current month (for navigation) const nextMonth = addMonths(currentDate, 1); const nextMonthView = getCalendarMonthView({ date: nextMonth, events: [], weekStartsOn: 0, excluded: [], viewStart: startOfMonth(nextMonth), viewEnd: endOfMonth(nextMonth), hourSegments: 2, dayStartHour: 0, dayEndHour: 23, weekendDays: [0, 6] });
Debug
Known issues
breakingAs a library in `0.x.x` versioning, `calendar-utils` may introduce breaking changes between minor versions (e.g., `0.11.0` to `0.12.0`) without adhering to strict semantic versioning. Always review the changelog when upgrading.
fix
Always pin exact versions (e.g., `"calendar-utils": "0.12.5"`) or use caret ranges cautiously, and consult release notes for migration guides during upgrades.
affects: >=0.0.0
gotchaThe library relies on peer dependencies for date manipulation (e.g., `date-fns`, `luxon`, `moment`). You must install one of these explicitly in your project, along with any necessary adapters if the library requires it (though for `calendar-utils` the functions directly accept standard Date objects or compatible date library types).
fix
Install your preferred date library: `npm install date-fns` or `npm install luxon` or `npm install moment`.
affects: >=0.0.0
gotchaIncorrect configuration of `weekStartsOn` or `weekendDays` can lead to unexpected calendar layouts, especially when mixing `calendar-utils` with UI components that have their own default settings.
fix
Ensure `weekStartsOn` (0 for Sunday, 1 for Monday) and `weekendDays` (array of day indexes, 0-6) are consistent across your `calendar-utils` configuration and any consuming UI library.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'date-fns' (or 'luxon' or 'moment')
A required peer dependency for date manipulation (e.g., date-fns) is not installed in your project.
fix
Install the missing date library: `npm install date-fns` or `npm install luxon` or `npm install moment`.
TypeError: getCalendarMonthView is not a function
This usually means you are attempting to use a CommonJS `require` statement on a library primarily designed for ESM, or using incorrect named/default import syntax.
fix
Ensure you are using ESM `import { getCalendarMonthView } from 'calendar-utils';` and your project supports ESM.
Argument of type 'string' is not assignable to parameter of type 'Date'.
The `calendar-utils` functions expect native JavaScript `Date` objects (or objects compatible with the chosen date library's `Date` type) for date parameters, not strings.
fix
Ensure all date inputs (e.g., `date`, `viewStart`, `viewEnd` arguments) are `new Date()` objects, or parsed by your chosen date library (e.g., `parseISO('2023-01-01')` from `date-fns`).
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
date-fnsrequiredRequired for date manipulation if chosen as the adapter. One of the peer dependencies must be installed and configured.
luxonrequiredRequired for date manipulation if chosen as the adapter. One of the peer dependencies must be installed and configured.
momentrequiredRequired for date manipulation if chosen as the adapter. One of the peer dependencies must be installed and configured.
Agent activity
15 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
calendar-utils — npm install calendar-utils · libregistry