ical-generator is a small piece of code which generates ical calendar files. I use this to generate subscriptionable calendar feeds.
npm install ical-generator
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.
varical=require('ical-generator'),http=require('http'),cal=ical({domain: 'github.com',name: 'my first iCal'});// overwrite domaincal.domain('sebbo.net');cal.createEvent({start: newDate(),end: newDate(newDate().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/');});varical=require('ical-generator'),// Create new Calendar and set optional fieldscal=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 valuescal.domain();// --> "sebbo.net"// create a new eventvarevent=cal.createEvent({start: newDate(),end: newDate(newDate().getTime()+3600000),timestamp: newDate(),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 stringcal.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: newDate(),end: newDate(newDate().getTime()+3600000),timestamp: newDate(),summary: 'My Event',organizer: 'Sebastian Pekarek <mail@example.com>'}]}).toString();Creates a new Calendar (ICalCalendar).
varical=require('ical-generator'),cal=ical();You can pass options to setup your calendar or use setters to do this.
varical=require('ical-generator'),cal=ical({domain: 'sebbo.net'});// is the same ascal=ical().domain('sebbo.net');// is the same ascal=ical();cal.domain('sebbo.net');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()).
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});// ORcal.prodId('//My Company//My Product//EN');Use this method to set your feed's name. Is used to fill NAME and X-WR-CALNAME in your iCal file.
Use this method to set your feed's URL.
varcal=ical().url('https://example.com/calendar.ical');Use this method to set your feed's timezone. Is used to fill TIMEZONE-ID and X-WR-TIMEZONE in your iCal.
varcal=ical().timezone('Europe/Berlin');Calendar method. May be any of the following: publish, request, reply, add, cancel, refresh, counter, declinecounter.
Use this method to set your feed's time to live. Is used to fill REFRESH-INTERVAL and X-PUBLISHED-TTL in your iCal.
varcal=ical().ttl(60*60*24);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.
varical=require('ical-generator'),cal=ical(),event=cal.createEvent({summary: 'My Event'});// overwrite event summaryevent.summary('Your Event');Add Events to calendar or return all attached events.
varcal=ical();cal.events([{start: newDate(),end: newDate(newDate().getTime()+3600000),summary: 'Example Event',description: 'It works ;)',url: 'http://sebbo.net/'}]);cal.events();// --> [ICalEvent]Save Calendar to disk asynchronously using fs.writeFile.
Save Calendar to disk synchronously using fs.writeFileSync.
Send Calendar to the User when using HTTP. See Quick Start above.
Return Calendar as a String.
Return a shallow copy of the calendar's options for JSON stringification. Can be used for persistance.
varcal=ical(),json=JSON.stringify(cal);// latercal=ical(json);Returns the ammount of events in the calendar.
Empty the Calender.
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.
Use this method to set the event's revision sequence number of the calendar component within a sequence of revisions.
Appointment date of beginning as Date object. This is required for all events!
Appointment date of end as Date object.
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).
Appointment date of creation as Date object. Default to new Date().
When allDay == true -> appointment is for the whole day
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).
Appointment is a repeating event
event.repeating({freq: 'MONTHLY',// requiredcount: 5,interval: 2,until: newDate('Jan 01 2014 00:00:00 UTC'),byDay: ['su','mo'],// repeat only sunday and mondaybyMonth: [1,2],// repeat only in january und february,byMonthDay: [1,15],// repeat only on the 1st and 15thexclude: [newDate('Dec 25 2013 00:00:00 UTC')]// exclude these dates});Appointment summary, defaults to empty string.
Appointment description
Some calendar apps may support HTML descriptions. Like in emails, supported HTML tags and styling is limited.
Appointment location
Appointment organizer
cal.organizer({name: 'Organizer\'s Name',email: 'organizer@example.com'});// ORcal.organizer('Organizer\'s Name <organizer@example.com>');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.
varical=require('ical-generator'),cal=ical(),event=cal.createEvent(),attendee=event.createAttendee({email: 'hui@example.com','name': 'Hui'});// overwrite attendee's email addressattendee.email('hui@example.net');// add another attendeeevent.createAttendee('Buh <buh@example.net>');Add Attendees to the event or return all attached attendees.
varevent=ical().createEvent();cal.attendees([{email: 'a@example.com',name: 'Person A'},{email: 'b@example.com',name: 'Person B'}]);cal.attendees();// --> [ICalAttendee, ICalAttendee]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.
varical=require('ical-generator'),cal=ical(),event=cal.createEvent(),alarm=event.createAlarm({type: 'display',trigger: 300});// add another alarmevent.createAlarm({type: 'audio',trigger: 300,// 5min before event});Add alarms to the event or return all attached alarms.
varevent=ical().createEvent();cal.alarms([{type: 'display',trigger: 600},{type: 'audio',trigger: 300}]);cal.alarms();// --> [ICalAlarm, ICalAlarm]Appointment URL
Appointment status. May be any of the following: confirmed, tentative, cancelled.
Use this method to set the attendee's name.
The attendee's email address. An email address is required for every attendee!
Set the attendee's RSVP expectation. May be one of the following: true, false
Set the attendee's role, defaults to REQ-PARTICIPANT. May be one of the following: req-participant, non-participant
Set the attendee's status. May be one of the following: accepted, tentative, declined, needs-action (See Section 4.2.12)
Set the attendee's type. May be one of the following: individual, group, resource, room, unknown (See Section 4.2.3)
Creates a new Attendee if passed object is not already an attendee. Will set the delegatedTo and delegatedFrom attributes.
varcal=ical(),event=cal.createEvent(),attendee=cal.createAttendee();attendee.delegatesTo({email: 'foo@bar.com',name: 'Foo'});Creates a new Attendee if passed object is not already an attendee. Will set the delegatedTo and delegatedFrom attributes.
varcal=ical(),event=cal.createEvent(),attendee=cal.createAttendee();attendee.delegatesFrom({email: 'foo@bar.com',name: 'Foo'});Use this method to set the alarm type. Right now, audio and display is supported.
Use this method to set the alarm time.
varcal=ical(),event=cal.createEvent(),alarm=cal.createAlarm();alarm.trigger(600);// -> 10 minutes before event startsalarm.trigger(newDate());// -> nowUse this method to set the alarm time.
varcal=ical(),event=cal.createEvent(),alarm=cal.createAlarm();alarm.triggerAfter(600);// -> 10 minutes after the event finishesalarm.triggerAfter(newDate());// -> nowUse this method to repeat the alarm.
varcal=ical(),event=cal.createEvent(),// repeat the alarm 4 times every 5 minutes…cal.createAlarm({repeat: 4,interval: 300});Use this method to set the alarm's interval.
varcal=ical(),event=cal.createEvent(),// repeat the alarm 4 times every 5 minutes…cal.createAlarm({repeat: 4,interval: 300});Alarm attachment; used to set the alarm sound if type = audio. Defaults to "Basso".
varcal=ical(),event=cal.createEvent(),event.createAlarm({attach: 'https://example.com/notification.aud'});// ORevent.createAlarm({attach: {uri: 'https://example.com/notification.aud',mime: 'audio/basic'}});Alarm description; used to set the alarm message if type = display. Defaults to the event's summary.
npm test
Copyright (c) Sebastian Pekarek under the MIT license.