Class ICalCalendar

Usually you get an ICalCalendar object like this:

import ical from 'ical-generator';
const calendar = ical();

But you can also use the constructor directly like this:

import {ICalCalendar} from 'ical-generator';
const calendar = new ICalCalendar();

Constructors

  • You can pass options to set up your calendar or use setters to do this.

     * import ical from 'ical-generator';

    // or use require:
    // const { default: ical } = require('ical-generator');


    const cal = ical({name: 'my first iCal'});

    // is the same as

    const cal = ical().name('my first iCal');

    // is the same as

    const cal = ical();
    cal.name('sebbo.net');

    cal.toString() would then produce the following string:

    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//sebbo.net//ical-generator//EN
    NAME:sebbo.net
    X-WR-CALNAME:sebbo.net
    END:VCALENDAR
    

    Parameters

    Returns ICalCalendar

Methods

  • Remove all events from the calendar without touching any other data like name or prodId.

    Returns this

    Since

    2.0.0-develop.1

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

    import ical from 'ical-generator';

    // or use require:
    // const { default: ical } = require('ical-generator');

    const cal = ical();
    const event = cal.createEvent({summary: 'My Event'});

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

    Parameters

    Returns ICalEvent

    Since

    0.2.0

  • Get your feed's description

    Returns null | string

    Since

    0.2.7

  • Set your feed's description

    Parameters

    • description: null | string

    Returns this

    Since

    0.2.7

  • Returns all events of this calendar.

    const 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]

    Returns ICalEvent[]

    Since

    0.2.0

  • Add multiple events to your calendar.

    const 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]

    Parameters

    Returns this

    Since

    0.2.0

  • Get the number of events added to your calendar

    Returns number

  • Get your feed's name

    Returns null | string

    Since

    0.2.0

  • Set your feed's name. Is used to fill NAME and X-WR-CALNAME in your iCal file.

    import ical from 'ical-generator';

    const cal = ical();
    cal.name('Next Arrivals');

    cal.toString();
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//sebbo.net//ical-generator//EN
    NAME:Next Arrivals
    X-WR-CALNAME:Next Arrivals
    END:VCALENDAR
    

    Parameters

    • name: null | string

    Returns this

    Since

    0.2.0

  • Get your feed's prodid. Will always return a string.

    Returns string

    Since

    0.2.0

  • Set your feed's prodid. prodid can be either a string like //sebbo.net//ical-generator//EN or a valid ICalCalendarProdIdData object. language is optional and defaults to EN.

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

    cal.toString() would then produce the following string:

    PRODID:-//My Company//My Product//EN
    

    Parameters

    Returns this

    Since

    0.2.0

  • Get current value of the CALSCALE attribute. It will return null if no value was set. The iCal standard specifies this as GREGORIAN if no value is present.

    Returns null | string

    Since

    1.8.0

  • Use this method to set your feed's CALSCALE attribute. There is no default value for this property and it will not appear in your iCal file unless set. The iCal standard specifies this as GREGORIAN if no value is present.

    cal.scale('gregorian');
    

    Parameters

    • scale: null | string

    Returns this

    Since

    1.8.0

  • Get current value of the SOURCE attribute.

    Returns null | string

    Since

    2.2.0-develop.1

  • Use this method to set your feed's SOURCE attribute. This tells the client where to refresh your feed.

    cal.source('http://example.com/my/original_source.ical');
    
    SOURCE;VALUE=URI:http://example.com/my/original_source.ical
    

    Parameters

    • source: null | string

    Returns this

    Since

    2.2.0-develop.1

  • Get the current calendar timezone

    Returns null | string

    Since

    0.2.0

  • Use this method to set your feed's timezone. Is used to fill TIMEZONE-ID and X-WR-TIMEZONE in your iCal export. Please not that all date values are treaded differently, if a timezone was set. See formatDate for details. If no time zone is specified, all information is output as UTC.

    cal.timezone('America/New_York');
    

    Parameters

    • timezone: null | string

    Returns this

  • Sets the time zone to be used in this calendar file for all times of all events. Please note that if the time zone is set, ical-generator assumes that all times are already in the correct time zone. Alternatively, a moment-timezone or a Luxon object can be passed with setZone, ical-generator will then set the time zone itself.

    For the best support of time zones, a VTimezone entry in the calendar is recommended, which informs the client about the corresponding time zones (daylight saving time, deviation from UTC, etc.). ical-generator itself does not have a time zone database, so an external generator is needed here.

    A VTimezone generator is a function that takes a time zone as a string and returns a VTimezone component according to the ical standard. For example, ical-timezones can be used for this:

    import ical from 'ical-generator';
    import {getVtimezoneComponent} from '@touch4it/ical-timezones';

    const cal = ical();
    cal.timezone({
    name: 'FOO',
    generator: getVtimezoneComponent
    });
    cal.createEvent({
    start: new Date(),
    timezone: 'Europe/London'
    });

    Parameters

    Returns this

  • Return a shallow copy of the calendar's options for JSON stringification. Third party objects like moment.js values or RRule objects are stringified as well. Can be used for persistence.

    const cal = ical();
    const json = JSON.stringify(cal);

    // later: restore calendar data
    cal = ical(JSON.parse(json));

    Returns ICalCalendarJSONData

    Since

    0.2.4

  • Return generated calendar as a string.

    const cal = ical();
    console.log(cal.toString()); // → BEGIN:VCALENDAR…

    Returns string

  • Get the current ttl duration in seconds

    Returns null | number

    Since

    0.2.5

  • 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.

    const cal = ical().ttl(60 * 60 * 24); // 1 day
    

    You can also pass a moment.js duration object. Zero, null or negative numbers will reset the ttl attribute.

    Parameters

    Returns this

    Since

    0.2.5

  • Get your feed's URL

    Returns null | string

    Since

    0.2.5

  • Set your feed's URL

    calendar.url('http://example.com/my/feed.ical');
    

    Parameters

    • url: null | string

    Returns this

    Since

    0.2.5

  • Set X-* attributes. Woun't filter double attributes, which are also added by another method (e.g. busystatus), so these attributes may be inserted twice.

    calendar.x([
    {
    key: "X-MY-CUSTOM-ATTR",
    value: "1337!"
    }
    ]);

    calendar.x([
    ["X-MY-CUSTOM-ATTR", "1337!"]
    ]);

    calendar.x({
    "X-MY-CUSTOM-ATTR": "1337!"
    });
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//sebbo.net//ical-generator//EN
    X-MY-CUSTOM-ATTR:1337!
    END:VCALENDAR
    

    Parameters

    • keyOrArray: Record<string, string> | [string, string][] | {
          key: string;
          value: string;
      }[]

    Returns this

    Since

    1.9.0

  • Set a X-* attribute. Woun't filter double attributes, which are also added by another method (e.g. busystatus), so these attributes may be inserted twice.

    calendar.x("X-MY-CUSTOM-ATTR", "1337!");
    
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//sebbo.net//ical-generator//EN
    X-MY-CUSTOM-ATTR:1337!
    END:VCALENDAR
    

    Parameters

    • keyOrArray: string
    • value: string

    Returns this

    Since

    1.9.0

  • Get all custom X-* attributes.

    Returns {
        key: string;
        value: string;
    }[]

    Since

    1.9.0

Generated using TypeDoc