immutable-ics v0.4.0
immutable-ics
Immutable iCalendar document creation using typed-immutable and Immutable.js.
Status
Installation
npm install --save immutable-icsQuick Guide
Import
Import the modules:
import { Component, Property } from 'immutable-ics'The following modules are available:
Component: Typed ImmutableRecordto build an iCalendar ComponentProperty: Typed ImmutableRecordto build an iCalendar Property
Create a component
Create a new component and add properties:
let calendar
let event
const versionProperty = new Property({ name: 'VERSION', value: 2 })
const dtstartProperty = new Property({
name: 'DTSTART',
parameters: { VALUE: 'DATE' },
value: new Date('1991-07-11 7:00:00')
})
calendar = new Component({ name: 'VCALENDAR' })
calendar = calendar.pushProperty(versionProperty)
event = new Component({ name: 'VEVENT' })
event = event.pushProperty(dtstartProperty)
calendar = calendar.pushComponent(event)Or instantiate everything at once:
const calendar = new Component({
name: 'VCALENDAR',
properties: [
new Property({ name: 'VERSION', value: 2 })
],
components: [
new Component({
name: 'VEVENT',
properties: [
new Property({
name: 'DTSTART',
parameters: { VALUE: 'DATE' },
value: new Date('1991-07-11 7:00:00')
})
]
})
]
})Generate iCalendar data
Call #toString on the Component or Property to get a string representation
of the component according to the iCalendar specifications.
calendar.toString()Generated data:
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTSTART;VALUE=DATE:19910711
END:VEVENT
END:VCALENDARThis string can then be saved to a file, sent to the user, etc.
API
Component
An Immutable Record with the following properties:
name: String: Name of the component (e.g. "VCALENDAR", "VEVENT")components: List<Component>: List ofComponentinstancesproperties: List<Property>: List ofPropertyinstances
All methods return a new instance of the component due to its backing on
Immutable's Record.
Extended Methods
Component.constructor({ name: String, components: (List<Component> | Array<Component>), properties: (List<Property> | Array<Property>) }): ComponentInstantiate a new
Componentwith initial values.componentsandpropertieswill be coerced to aList.Component.prototype.pushComponent(component: Component): ComponentPush a
Componentto the list of components.Component.prototype.pushProperty(property: Property): ComponentPush a
Propertyto the list of properties.Component.prototype.clear(): ComponentClear all components and properties from the component.
Component.prototype.clearComponents(): ComponentClear all components from the component.
Component.prototype.clearProperties(): ComponentClear all properties from the component.
Component.prototype.toString(): StringGet a string representation of the component according to the iCalendar specifications.
Property
An Immutable Record with the following properties:
name: String: Name of the property (e.g. "DTSTART", "SUMMARY")parameters: Map<String, Any>: Property parameters (e.g. "VALUE")transform: Boolean = true: Explicit determiner if the value is transformedvalue: Any: Value of the property
All methods return a new instance of the property due to its backing on
Immutable's Record.
Extended Methods
Property.constructor({ name: String, parameters: (Object | Map<String, Any>), transform: Boolean = true, value: Any }): PropertyInstantiate a new
Propertywith initial values.parameterswill be coerced into aMap.Property.prototype.getTransformedValue(): StringGet the transformed value of the property's value. Transformations are conveniences to generate valid iCalendar data from JavaScript objects.
For example, providing a
Dateobject to aDTSTAMPproperty value will transform as such:const dtstampProperty = new Property({ name: 'DTSTAMP' parameters: { VALUE: 'DATE' }, value: new Date('1991-07-11 7:00:00') }) dtstampProperty.toString() // => DTSTAMP;VALUE=DATE:19910711Property.prototype.toString(): StringGet a string representation of the property according to the iCalendar specifications.