Options
All
  • Public
  • Public/Protected
  • All
Menu

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();

Hierarchy

  • ICalCalendar

Index

Constructors

constructor

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

     * import ical from 'ical-generator';
    
    // or use require:
    // const ical = require('ical-generator').default;
    
    
    const cal = ical({domain: 'sebbo.net'});
    
    // is the same as
    
    const cal = ical().domain('sebbo.net');
    
    // is the same as
    
    const cal = ical();
    cal.domain('sebbo.net');
    

    Parameters

    Returns ICalCalendar

Methods

clear

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

    since

    2.0.0-develop.1

    Returns ICalCalendar

createEvent

  • 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 ical = require('ical-generator').default;
    
    const cal = ical();
    const event = cal.createEvent({summary: 'My Event'});
    
    // overwrite event summary
    event.summary('Your Event');
    
    since

    0.2.0

    Parameters

    Returns ICalEvent

description

  • description(): null | string
  • description(description: null | string): ICalCalendar
  • Get your feed's description

    since

    0.2.7

    Returns null | string

  • Set your feed's description

    since

    0.2.7

    Parameters

    • description: null | string

    Returns ICalCalendar

events

  • 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]
    
    since

    0.2.0

    Returns ICalEvent[]

  • 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]
    
    since

    0.2.0

    Parameters

    Returns ICalCalendar

length

  • length(): number
  • Get the number of events added to your calendar

    Returns number

method

name

  • name(): null | string
  • name(name: null | string): ICalCalendar
  • Get your feed's name

    since

    0.2.0

    Returns null | string

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

    since

    0.2.0

    Parameters

    • name: null | string

    Returns ICalCalendar

prodId

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

    since

    0.2.0

    Returns string

  • 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
    });
    
    since

    0.2.0

    Parameters

    Returns ICalCalendar

save

  • save(path: string): Promise<void>
  • save(path: string, cb?: (err: null | ErrnoException) => void): ICalCalendar
  • Save ical file using fs/promises. Only works in node.js environments.

    await calendar.save('./calendar.ical');
    

    Parameters

    • path: string

    Returns Promise<void>

  • Save ical file with fs.writeFile. Only works in node.js environments.

    calendar.save('./calendar.ical', err => {
        console.log(err);
    });
    

    Parameters

    • path: string
    • Optional cb: (err: null | ErrnoException) => void
        • (err: null | ErrnoException): void
        • Parameters

          • err: null | ErrnoException

          Returns void

    Returns ICalCalendar

saveSync

scale

  • scale(): null | string
  • scale(scale: null | string): ICalCalendar
  • 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.

    since

    1.8.0

    Returns null | string

  • 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');
    
    since

    1.8.0

    Parameters

    • scale: null | string

    Returns ICalCalendar

serve

  • serve(response: ServerResponse, filename?: string): ICalCalendar
  • Send calendar to the user when using HTTP using the passed ServerResponse object. Use second parameter filename to change the filename, which defaults to 'calendar.ics'.

    Parameters

    • response: ServerResponse

      HTTP Response object which is used to send the calendar

    • filename: string = 'calendar.ics'

    Returns ICalCalendar

timezone

  • Get the current calendar timezone

    since

    0.2.0

    Returns null | string

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

    cal.timezone('America/New_York');
    
    since

    0.2.0

    Parameters

    • timezone: null | string

    Returns ICalCalendar

  • 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 = new ICalCalendar();
    cal.timezone({
        name: 'FOO',
        generator: getVtimezoneComponent
    });
    cal.createEvent({
        start: new Date(),
        timezone: 'Europe/London'
    });
    
    since

    2.0.0

    Parameters

    Returns ICalCalendar

toBlob

  • toBlob(): Blob
  • Generates a blob to use for downloads or to generate a download URL. Only supported in browsers supporting the Blob API.

    Unfortunately, because node.js has no Blob implementation (they have Buffer instead), this method is currently untested. Sorry Dave…

    since

    1.9.0

    Returns Blob

toJSON

  • 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));
    
    since

    0.2.4

    Returns ICalCalendarJSONData

toString

  • toString(): string
  • Return generated calendar as a string.

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

    Returns string

toURL

  • toURL(): string
  • Returns a URL to download the ical file. Uses the Blob object internally, so it's only supported in browsers supporting the Blob API.

    Unfortunately, because node.js has no Blob implementation (they have Buffer instead), this can't be tested right now. Sorry Dave…

    since

    1.9.0

    Returns string

ttl

  • ttl(): null | number
  • ttl(ttl: null | number | Duration): ICalCalendar
  • Get the current ttl duration in seconds

    since

    0.2.5

    Returns null | number

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

    since

    0.2.5

    Parameters

    • ttl: null | number | Duration

    Returns ICalCalendar

url

  • url(): null | string
  • url(url: null | string): ICalCalendar
  • Get your feed's URL

    since

    0.2.5

    Returns null | string

  • Set your feed's URL

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

    0.2.5

    Parameters

    • url: null | string

    Returns ICalCalendar

x

  • x(keyOrArray: [string, string][] | Record<string, string> | { key: string; value: string }[]): ICalCalendar
  • x(keyOrArray: string, value: string): ICalCalendar
  • x(): { key: string; value: string }[]
  • 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!"
    });
    
    since

    1.9.0

    Parameters

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

    Returns ICalCalendar

  • 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!");
    
    since

    1.9.0

    Parameters

    • keyOrArray: string
    • value: string

    Returns ICalCalendar

  • Get all custom X-* attributes.

    since

    1.9.0

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

Legend

  • Constructor
  • Method
  • Property

Generated using TypeDoc