ical-expander is a JavaScript/TypeScript library designed for parsing and expanding iCalendar (ICS) data. It acts as a wrapper around the `ical.js` library, simplifying the complexities of recurring events by automatically handling `EXDATE` (excluded occurrences), `RRULE` (recurrence rules), and `RECURRENCE-ID` (overridden instances). The package also incorporates timezone definitions from the IANA Time Zone Database, ensuring correct parsing even when timezone information is absent from the ICS file itself. The current stable version is 3.2.0, with a release cadence that indicates active maintenance and incremental improvements, such as recent updates to timezone data and fixes related to `ical.js` versions. A key consideration is its synchronous processing model, which can block the JavaScript event loop when dealing with large ICS files or high `maxIterations` values, requiring careful usage, particularly in performance-sensitive applications. Its primary differentiator is abstracting away the intricacies of `ical.js` for common expansion tasks.
npm install ical-expanderVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to load an ICS file, parse it using IcalExpander, and then retrieve all events and occurrences within a specified date range, logging their start dates and summaries.
For large ICS files, consider processing in a worker thread (e.g., Worker Threads in Node.js, Web Workers in browsers) to offload the synchronous work from the main thread. Keep `maxIterations` to a reasonable, bounded value.
Always provide a finite, reasonable `maxIterations` value (default is 1000). Only set to `0` if you are absolutely certain of the ICS file's structure and performance implications, and can implement external timeouts.
Configure your build tools (e.g., Babel, Webpack) to transpile `node_modules/ical-expander` if necessary for your target environments.
Thoroughly test your application's event parsing logic after upgrading to `3.0.0` or later, especially for calendars containing events with modified recurring instances (`RECURRENCE-ID`).
If your application is sensitive to precise timezone interpretations, verify event parsing for critical dates and timezones after upgrading to `3.1.0` or later.
For ESM/TypeScript: `import { IcalExpander } from 'ical-expander';`. For CommonJS: `const IcalExpander = require('ical-expander');`.Ensure the ICS content is valid. Add checks for `events.events` and `events.occurrences` being defined before attempting to map them, e.g., `(events.events || []).map(...)`.
Reduce `maxIterations` to a reasonable value. For very large files, process the ICS data in a Web Worker (browser) or Worker Thread (Node.js) to avoid blocking the main event loop.