7.1.0 • Published 3 days ago

ical-generator v7.1.0

Weekly downloads
45,772
License
MIT
Repository
github
Last release
3 days ago

ical-generator

License Status Test Coverage

ical-generator is a small piece of code which generates ical calendar files. I use this to generate subscriptionable calendar feeds.

Installation

npm install ical-generator

Upgrade from 0.1.x

ical-generator 0.2.0 introduces a completely new API, but because you guys used 0.1.x a lot, the old API still works. So you should be able to upgrade from ical-generator 0.1.x to 0.2.0 without any code changes. In case you need the old API docs, you can find the deprecated documentation here.

In case you have any issues with the new API, feel free to create an issue.

Quick Start

var ical = require('ical-generator'),
	http = require('http'),
	cal = ical({domain: 'github.com', name: 'my first iCal'});

// overwrite domain
cal.domain('sebbo.net');

cal.createEvent({
	start: new Date(),
	end: new Date(new Date().getTime() + 3600000),
	summary: 'Example Event',
	description: 'It works ;)',
	location: 'my room',
	url: 'http://sebbo.net/'
});

http.createServer(function(req, res) {
	cal.serve(res);
}).listen(3000, '127.0.0.1', function() {
    console.log('Server running at http://127.0.0.1:3000/');
});

Just another example

var ical = require('ical-generator'),

    // Create new Calendar and set optional fields
    cal = ical({
        domain: 'sebbo.net',
        prodId: {company: 'superman-industries.com', product: 'ical-generator'},
        name: 'My Testfeed',
        timezone: 'Europe/Berlin'
    });

// You can also set values like this…
cal.domain('sebbo.net');

// … or get values
cal.domain(); // --> "sebbo.net"

// create a new event
var event = cal.createEvent({
    start: new Date(),
    end: new Date(new Date().getTime() + 3600000),
    timestamp: new Date(),
    summary: 'My Event',
    organizer: 'Sebastian Pekarek <mail@example.com>'
});

// like above, you can also set/change values like this…
event.summary('My Super Mega Awesome Event');

// get the iCal string
cal.toString(); // --> "BEGIN:VCALENDAR…"


// You can also create events directly with ical()
cal = ical({
    domain: 'sebbo.net',
    prodId: '//superman-industries.com//ical-generator//EN',
    events: [
        {
            start: new Date(),
            end: new Date(new Date().getTime() + 3600000),
            timestamp: new Date(),
            summary: 'My Event',
            organizer: 'Sebastian Pekarek <mail@example.com>'
        }
    ]
}).toString();

API

ical-generator

ical(Object options)

Creates a new Calendar (ICalCalendar).

var ical = require('ical-generator'),
    cal = ical();

You can pass options to setup your calendar or use setters to do this.

var ical = require('ical-generator'),
    cal = ical({domain: 'sebbo.net'});

// is the same as

cal = ical().domain('sebbo.net');

// is the same as

cal = ical();
cal.domain('sebbo.net');

Calendar

domain(String domain)

Use this method to set your server's hostname. It will be used to generate the feed's UID. Default hostname is your server's one (require('os').hostname()).

prodId(String|Object prodId)

Use this method to overwrite the default Product Identifier (//sebbo.net//ical-generator//EN). prodId can be ether a valid Product Identifier or an object:

cal.prodId({
	company: 'My Company',
	product: 'My Product',
	language: 'EN' // optional, defaults to EN
});

// OR

cal.prodId('//My Company//My Product//EN');

name(String name)

Use this method to set your feed's name. Is used to fill NAME and X-WR-CALNAME in your iCal file.

url(String url)

Use this method to set your feed's URL.

var cal = ical().url('https://example.com/calendar.ical');

timezone(String timezone)

Use this method to set your feed's timezone. Is used to fill TIMEZONE-ID and X-WR-TIMEZONE in your iCal.

var cal = ical().timezone('Europe/Berlin');

method(String method)

Calendar method. May be any of the following: publish, request, reply, add, cancel, refresh, counter, declinecounter.

ttl(Number ttl)

Use this method to set your feed's time to live (in seconds). Is used to fill REFRESH-INTERVAL and X-PUBLISHED-TTL in your iCal.

var cal = ical().ttl(60 * 60 * 24);

createEvent(Object options)

Creates a new Event (ICalEvent) and returns it. Use options to prefill the event's attributes. Calling this method without options will create an empty event.

var ical = require('ical-generator'),
    cal = ical(),
    event = cal.createEvent({summary: 'My Event'});

// overwrite event summary
event.summary('Your Event');

events(Object events)

Add Events to calendar or return all attached events.

var cal = ical();
cal.events([
    {
        start: new Date(),
        end: new Date(new Date().getTime() + 3600000),
        summary: 'Example Event',
        description: 'It works ;)',
        url: 'http://sebbo.net/'
    }
]);

cal.events(); // --> [ICalEvent]

save(String file, Function cb)

Save Calendar to disk asynchronously using fs.writeFile.

saveSync(String file)

Save Calendar to disk synchronously using fs.writeFileSync.

serve(http.ServerResponse response)

Send Calendar to the User when using HTTP. See Quick Start above.

toString()

Return Calendar as a String.

toJSON()

Return a shallow copy of the calendar's options for JSON stringification. Can be used for persistance.

var cal = ical(),
    json = JSON.stringify(cal);
    
// later
cal = ical(json);

length()

Returns the ammount of events in the calendar.

clear()

Empty the Calender.

Event

uid(String|Number uid) or id(String|Number id)

Use this method to set the event's ID. If not set, an UID will be generated randomly. When output, the ID will be suffixed with '@' + your calendar's domain.

sequence(Number sequence)

Use this method to set the event's revision sequence number of the calendar component within a sequence of revisions.

start(Date start)

Appointment date of beginning as Date object. This is required for all events!

end(Date end)

Appointment date of end as Date object.

timezone(String timezone)

Use this method to set your event's timezone using the TZID property parameter on start and end dates, as per date-time form #3 in section 3.3.5 of RFC 554.

This and the 'floating' flag (see below) are mutually exclusive, and setting a timezone will unset the 'floating' flag. If neither 'timezone' nor 'floating' are set, the date will be output with in UTC format (see date-time form #2 in section 3.3.5 of RFC 554).

timestamp(Date stamp) or stamp(Date stamp)

Appointment date of creation as Date object. Default to new Date().

allDay(Boolean allDay)

When allDay == true -> appointment is for the whole day

floating(Boolean floating)

Appointment is a "floating" time. From section 3.3.12 of RFC 554:

Time values of this type are said to be "floating" and are not bound to any time zone in particular. They are used to represent the same hour, minute, and second value regardless of which time zone is currently being observed. For example, an event can be defined that indicates that an individual will be busy from 11:00 AM to 1:00 PM every day, no matter which time zone the person is in. In these cases, a local time can be specified.

This and the 'timezone' setting (see above) are mutually exclusive, and setting the floating flag will unset the 'timezone'. If neither 'timezone' nor 'floating' are set, the date will be output with in UTC format (see date-time form #2 in section 3.3.5 of RFC 554).

repeating(Object repeating)

Appointment is a repeating event

event.repeating({
    freq: 'MONTHLY', // required
    count: 5,
    interval: 2,
    until: new Date('Jan 01 2014 00:00:00 UTC'),
    byDay: ['su', 'mo'], // repeat only sunday and monday
    byMonth: [1, 2], // repeat only in january und february,
    byMonthDay: [1, 15], // repeat only on the 1st and 15th
    exclude: [new Date('Dec 25 2013 00:00:00 UTC')] // exclude these dates
});

summary(String summary)

Appointment summary, defaults to empty string.

description(String description)

Appointment description

htmlDescription(String htmlDescription)

Some calendar apps may support HTML descriptions. Like in emails, supported HTML tags and styling is limited.

location(String location)

Appointment location

organizer(String|Object organizer)

Appointment organizer

cal.organizer({
    name: 'Organizer\'s Name',
    email: 'organizer@example.com'
});

// OR

cal.organizer('Organizer\'s Name <organizer@example.com>');

createAttendee(Object options)

Creates a new Attendee (ICalAttendee) and returns it. Use options to prefill the attendee's attributes. Calling this method without options will create an empty attendee.

var ical = require('ical-generator'),
    cal = ical(),
    event = cal.createEvent(),
    attendee = event.createAttendee({email: 'hui@example.com', 'name': 'Hui'});

// overwrite attendee's email address
attendee.email('hui@example.net');

// add another attendee
event.createAttendee('Buh <buh@example.net>');

attendees(Object attendees)

Add Attendees to the event or return all attached attendees.

var event = ical().createEvent();
cal.attendees([
    {email: 'a@example.com', name: 'Person A'},
    {email: 'b@example.com', name: 'Person B'}
]);

cal.attendees(); // --> [ICalAttendee, ICalAttendee]

createAlarm(Object options)

Creates a new Alarm (ICalAlarm) and returns it. Use options to prefill the alarm's attributes. Calling this method without options will create an empty alarm.

var ical = require('ical-generator'),
    cal = ical(),
    event = cal.createEvent(),
    alarm = event.createAlarm({type: 'display', trigger: 300});

// add another alarm
event.createAlarm({
    type: 'audio',
    trigger: 300, // 5min before event
});

alarms(Object alarms)

Add alarms to the event or return all attached alarms.

var event = ical().createEvent();
cal.alarms([
    {type: 'display', trigger: 600},
    {type: 'audio', trigger: 300}
]);

cal.attendees(); // --> [ICalAlarm, ICalAlarm]

url(String url)

Appointment URL

status(String status)

Appointment status. May be any of the following: confirmed, tentative, cancelled.

created(Date created)

Date object of the time the appointment was created.

lastModified(Date lastModified)

Date object of the time the appointent was modified last.

Attendee

name(String name)

Use this method to set the attendee's name.

email(String email)

The attendee's email address. An email address is required for every attendee!

role(String role)

Set the attendee's role, defaults to REQ-PARTICIPANT. May be one of the following: req-participant, non-participant

status(String status)

Set the attendee's status. May be one of the following: accepted, tentative, declined

type(String type)

Set the attendee's type. May be one of the following: individual, group, resource, room, unknown (See Section 4.2.3)

delegatesTo(ICalAttendee|Object attendee)

Creates a new Attendee if passed object is not already an attendee. Will set the delegatedTo and delegatedFrom attributes.

var cal = ical(),
    event = cal.createEvent(),
    attendee = cal.createAttendee();

attendee.delegatesTo({email: 'foo@bar.com', name: 'Foo'});

delegatesFrom(ICalAttendee|Object attendee)

Creates a new Attendee if passed object is not already an attendee. Will set the delegatedTo and delegatedFrom attributes.

var cal = ical(),
    event = cal.createEvent(),
    attendee = cal.createAttendee();

attendee.delegatesFrom({email: 'foo@bar.com', name: 'Foo'});

Alarm

type(String type)

Use this method to set the alarm type. Right now, audio and display is supported.

trigger(Number|Date trigger) / triggerBefore(Number|Date trigger)

Use this method to set the alarm time.

var cal = ical(),
    event = cal.createEvent(),
    alarm = cal.createAlarm();

alarm.trigger(600); // -> 10 minutes before event starts
alarm.trigger(new Date()); // -> now

triggerAfter(Number|Date trigger)

Use this method to set the alarm time.

var cal = ical(),
    event = cal.createEvent(),
    alarm = cal.createAlarm();

alarm.triggerAfter(600); // -> 10 minutes after the event finishes
alarm.triggerAfter(new Date()); // -> now

repeat(Number repeat)

Use this method to repeat the alarm.

var cal = ical(),
    event = cal.createEvent(),

// repeat the alarm 4 times every 5 minutes…
cal.createAlarm({
    repeat: 4,
    interval: 300
});

interval(Number interval)

Use this method to set the alarm's interval.

var cal = ical(),
    event = cal.createEvent(),

// repeat the alarm 4 times every 5 minutes…
cal.createAlarm({
    repeat: 4,
    interval: 300
});

attach(String|Object attach)

Alarm attachment; used to set the alarm sound if type = audio. Defaults to "Basso".

var cal = ical(),
    event = cal.createEvent(),

event.createAlarm({
    attach: 'https://example.com/notification.aud'
});

// OR

event.createAlarm({
    attach: {
        uri: 'https://example.com/notification.aud',
        mime: 'audio/basic'
    }
});

description(String| description)

Alarm description; used to set the alarm message if type = display. Defaults to the event's summary.

Tests

npm test

Copyright and license

Copyright (c) Sebastian Pekarek under the MIT license.

7.2.0-develop.3

3 days ago

7.2.0-develop.2

3 days ago

7.2.0-develop.1

3 days ago

7.1.0

4 days ago

7.1.0-develop.3

5 days ago

7.1.0-develop.2

11 days ago

7.1.0-develop.1

19 days ago

7.0.1-develop.2

25 days ago

7.0.1-develop.1

1 month ago

7.0.0

1 month ago

7.0.0-develop.6

1 month ago

7.0.0-develop.5

1 month ago

7.0.0-develop.4

2 months ago

7.0.0-develop.2

2 months ago

7.0.0-develop.3

2 months ago

6.0.2-develop.13

2 months ago

7.0.0-develop.1

2 months ago

6.0.2-develop.10

2 months ago

6.0.2-develop.11

2 months ago

6.0.2-develop.12

2 months ago

6.0.2-develop.9

2 months ago

6.0.2-develop.8

2 months ago

6.0.2-develop.7

2 months ago

6.0.2-develop.6

2 months ago

6.0.2-develop.5

2 months ago

6.0.2-develop.4

3 months ago

6.0.2-develop.3

3 months ago

6.0.2-develop.2

3 months ago

6.0.2-develop.1

3 months ago

6.0.1-develop.8

3 months ago

6.0.1-develop.9

3 months ago

6.0.1-develop.10

3 months ago

6.0.1

3 months ago

6.0.1-develop.7

4 months ago

6.0.1-develop.6

4 months ago

6.0.1-develop.5

4 months ago

6.0.1-develop.4

4 months ago

6.0.1-develop.1

6 months ago

6.0.1-develop.2

5 months ago

6.0.1-develop.3

5 months ago

6.0.0

6 months ago

6.0.0-develop.1

6 months ago

6.0.0-develop.2

6 months ago

6.0.0-develop.4

6 months ago

5.0.2-develop.2

7 months ago

5.0.2-develop.1

8 months ago

5.0.1

8 months ago

5.0.0

10 months ago

5.0.0-develop.1

10 months ago

5.0.1-develop.1

9 months ago

4.1.0-develop.1

12 months ago

4.1.0-develop.2

12 months ago

4.1.0-develop.3

12 months ago

4.1.0

12 months ago

4.0.0

1 year ago

4.0.0-develop.1

1 year ago

4.0.0-develop.2

1 year ago

3.6.2-develop.4

1 year ago

3.6.2-develop.2

1 year ago

3.6.2-develop.3

1 year ago

3.6.1-develop.1

1 year ago

3.6.1-develop.2

1 year ago

3.6.1-develop.3

1 year ago

3.6.1

1 year ago

3.6.0

2 years ago

3.6.0-develop.1

2 years ago

3.6.2-develop.1

1 year ago

3.5.2

2 years ago

3.5.2-develop.2

2 years ago

3.5.2-develop.3

2 years ago

3.5.2-develop.1

2 years ago

3.4.4-develop.7

2 years ago

3.4.4-develop.8

2 years ago

3.4.4-develop.1

2 years ago

3.4.4-develop.2

2 years ago

3.4.4-develop.3

2 years ago

3.4.4-develop.4

2 years ago

3.4.4-develop.5

2 years ago

3.4.4-develop.6

2 years ago

3.5.1-develop.1

2 years ago

3.5.1

2 years ago

3.5.0

2 years ago

3.5.0-develop.1

2 years ago

3.4.3

2 years ago

3.4.2

2 years ago

3.4.3-develop.1

2 years ago

3.4.3-develop.2

2 years ago

3.4.2-develop.2

2 years ago

3.4.2-develop.3

2 years ago

3.4.1-develop.1

2 years ago

3.4.0

2 years ago

3.3.0-develop.1

2 years ago

3.4.1

2 years ago

3.3.0

2 years ago

3.4.2-develop.1

2 years ago

3.2.1-develop.1

2 years ago

3.1.1-develop.1

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.1.1

2 years ago

3.2.0-develop.2

2 years ago

3.2.0-develop.1

2 years ago

3.1.0

2 years ago

3.1.0-develop.2

2 years ago

3.1.0-develop.1

2 years ago

3.0.2-develop.2

2 years ago

3.0.2-develop.1

3 years ago

3.0.1

3 years ago

3.0.1-develop.4

3 years ago

3.0.1-develop.3

3 years ago

3.0.1-develop.2

3 years ago

3.0.1-develop.1

3 years ago

3.0.0-develop.8

3 years ago

3.0.0

3 years ago

3.0.0-develop.7

3 years ago

3.0.0-develop.6

3 years ago

3.0.0-develop.5

3 years ago

3.0.0-develop.4

3 years ago

3.0.0-develop.3

3 years ago

3.0.0-develop.2

3 years ago

3.0.0-develop.1

3 years ago

2.0.0

3 years ago

2.1.1-develop.1

3 years ago

2.0.1-develop.3

3 years ago

2.0.1-develop.1

3 years ago

2.0.1-develop.2

3 years ago

2.2.0

3 years ago

2.1.0-develop.6

3 years ago

2.1.0-develop.5

3 years ago

2.1.0-develop.4

3 years ago

2.1.0-develop.2

3 years ago

2.1.0-develop.1

3 years ago

2.2.0-develop.1

3 years ago

2.1.0

3 years ago

2.0.0-develop.22

3 years ago

2.0.0-develop.21

3 years ago

2.0.0-develop.20

3 years ago

2.0.0-develop.19

3 years ago

2.0.0-develop.18

3 years ago

2.0.0-develop.17

3 years ago

2.0.0-develop.15

3 years ago

2.0.0-develop.16

3 years ago

2.0.0-develop.14

3 years ago

2.0.0-develop.13

3 years ago

2.0.0-develop.11

3 years ago

2.0.0-develop.12

3 years ago

2.0.0-develop.10

3 years ago

1.3.0-develop.4

3 years ago

2.0.0-develop.8

3 years ago

2.0.0-develop.9

3 years ago

2.0.0-develop.2

3 years ago

2.0.0-develop.3

3 years ago

2.0.0-develop.1

3 years ago

2.0.0-develop.6

3 years ago

2.0.0-develop.7

3 years ago

2.0.0-develop.4

3 years ago

2.0.0-develop.5

3 years ago

1.3.0-develop.3

3 years ago

1.3.0-develop.2

3 years ago

1.3.0-develop.1

3 years ago

1.15.4

3 years ago

1.15.3

3 years ago

1.15.2

3 years ago

1.15.1

4 years ago

1.15.0

4 years ago

1.14.0

4 years ago

1.13.0

4 years ago

1.12.2

4 years ago

1.12.1

4 years ago

1.12.0

4 years ago

1.11.0

4 years ago

1.10.0

4 years ago

1.9.4

4 years ago

1.9.3

4 years ago

1.9.2

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago

1.8.3

4 years ago

1.8.2

4 years ago

1.8.1

5 years ago

1.8.0

5 years ago

1.7.3

5 years ago

1.7.2

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.5-0

6 years ago

1.0.4

6 years ago

1.0.4-0

6 years ago

1.0.3

6 years ago

1.0.3-0

6 years ago

1.0.2

6 years ago

1.0.2-6

6 years ago

1.0.2-5

6 years ago

1.0.2-4

6 years ago

1.0.2-3

6 years ago

1.0.2-2

6 years ago

1.0.2-1

6 years ago

1.0.1

6 years ago

1.0.1-2

6 years ago

1.0.1-1

6 years ago

1.0.0-4

6 years ago

1.0.0-3

6 years ago

1.0.0

6 years ago

1.0.0-2

6 years ago

1.0.0-1

6 years ago

1.0.2-0

6 years ago

1.0.1-0

6 years ago

1.0.0-0

6 years ago

0.3.0-dev.6

6 years ago

0.3.0-dev.5

6 years ago

0.3.0-dev.4

6 years ago

0.3.0-dev.3

6 years ago

0.3.0-dev.2

6 years ago

0.3.0-dev.1

6 years ago

0.3.0-dev.0

6 years ago

0.3.0-dev

6 years ago

0.2.10

7 years ago

0.2.9

7 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

9 years ago

0.2.4-dev

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.10

9 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago