Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

ikalendar

0.4.1 • Public • Published

iKalendar

NPM

Build Status

IMPORTANT: This is an early stage release and project structure can change greatly!

Parser and builder for iCalendar data format

Table of Contents

Install

npm instal ikalendar

Usage

Builder

import { Builder, Calendar } from 'ikalendar'
 
const calendar: Calendar = {
    version: '2.0',
    prodId: 'Awesome project prodId',
    events: [
        {
            start: '20101231T083000Z',
            uid: 'uid1@example.com'
        }
    ]
}
 
const builder = new Builder(calendar)
builder.build()
 
// Returns:
// 
// BEGIN:VCALENDAR
// VERSION:2.0
// PRODID:Awesome project prodId
// BEGIN:VEVENT
// DTSTAMP:20101231T083000Z
// UID:uid1@example.com
// END:VEVENT
// END:VCALENDAR

Parser

import { Parser } from 'ikalendar'
 
const str = `BEGIN:VCALENDAR
VERSION:2.0
PRODID:Awesome project prodId
BEGIN:VEVENT
DTSTAMP:20101231T083000Z
UID:uid1@example.com
END:VEVENT
END:VCALENDAR
`
 
const parser = new Parser(str)
parser.parse()
 
// Returns:
// 
// {
//     version: '2.0',
//     prodId: 'Awesome project prodId',
//     events: [
//         {
//             start: '20101231T083000Z',
//             uid: 'uid1@example.com'
//         }
//     ]
// }

Types

Date

iCal format supports multiple different Date/Date-Time formats, iKalendar gives you opportunity to use any of them with some restrictions.

I'll use DTSTART property for this example. You can create this property multiple ways:

  1. Plain string:
    • In iCal local time format 'YYYYMMDDTHHmmss'
      start:'19980118T230000'
      // DTSTART:19980118T230000
    • Any other moment.js recognizable format, gets parsed to UTC
      start:'1998-01-18T09:00:00+0200'
      // DTSTART:19980118T070000Z
  2. Object (ComplexDate) with following attributes:
    type ComplexDate = {
        type?: 'DATE-TIME' | 'DATE'
        tzId?: string
        value: string
    }
    • Passing tzId keeps time in that timezone
    start:{value: '1998-01-18T02:54:36-08:00', tzId: 'America/Los_Angeles'}
    // DTSTART;TZID=America/Los_Angeles:20200217T025436
    • Passing only value converts it once again to UTC
    start:{value: '1998-01-18T09:00:00+0200'}
    // DTSTART:19980118T070000Z
    • You can also specify type: 'DATE'
    start:{value: '1998-01-18T23:00:00', type: 'DATE'}
    // DTSTART:19980118
    • Or use all three attributes:
    start:{value: '1998-03-01T09:00:00+0100', type: 'DATE-TIME', tzId: 'Europe/Bratislava'}
    // DTSTART;VALUE=DATE-TIME;TZID=Europe/Bratislava:19980301T090000

License

This project is licensed under the ISC License - see the LICENSE.md file for details

Install

npm i ikalendar

DownloadsWeekly Downloads

7

Version

0.4.1

License

ISC

Unpacked Size

54.2 kB

Total Files

72

Last publish

Collaborators

  • avatar