/ics-js

Create ICS files in JavaScript

Primary LanguageJavaScript

ics-js

Create ICS files in ES6.

Status

npm version Build Status

Installation

npm install ics-js

Usage

Import the module:

import ICS from 'ics-js';

Create a component

const cal = new ICS.VCALENDAR();

The following components are implemented:

  • VCALENDAR
  • VEVENT
  • VALARM
  • VTODO

Add properties to a component

// Component#addProp(name, value, props)
//
// name: Name of the property
// value: Value of the property
// props: Object with properties for the property

cal.addProp('VERSION', 2) // Number(2) is converted to '2.0'
cal.addProp('PRODID', 'XYZ Corp');

Each component contains a list of property validations. Only valid properties can be added according to the RFC 5545 spec.

The following properties are implemented:

Name Input Output
CATEGORIES Array<String> Array items separated by ,
CREATED Date Formatted date to spec
DTEND Date Formatted date to spec
DTSTAMP Date Formatted date to spec
DTSTART Date Formatted date to spec
DUE Date Formatted date to spec
EXDATE Array<Date> Array items separated by , formatted to spec
GEO Array<Float> Array items separated by ; (should be [x, y])
LAST-MODIFIED Date Formatted date to spec
RDATE Date Formatted date to spec
TRANSP Boolean TRANSPARENT if true, OPAQUE if false
UID String or none If no input is provided, generates a random GUID
VERSION Number Float with 1 decimal to spec

All other properties (e.g. SUMMARY, LOCATION) are stored as-is without transformations.

Nest a component

const event = new ICS.VEVENT();
event.addProp('UID');
event.addProp('DTSTAMP', new Date('2015-07-18 10:00:00'), { VALUE: 'DATE-TIME' });

cal.addComponent(event);

Each component contains a list of valid nested components. Only valid components can be nested according to the RFC 5545 spec.

Generate ICS data

cal.toString(); // Returns a string
cal.toBlob(); // Returns a Blob
cal.toBase64(); // Returns a Promise with a base64 string as the resolved value

Acknowledgements

Inspired by nwcell/ics.js