Options
All
  • Public
  • Public/Protected
  • All
Menu

Usually you get an ICalCalendar object like this:

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

Hierarchy

  • ICalEvent

Index

Constructors

constructor

  • Constructor of [[ICalEvent]. The calendar reference is required to query the calendar's timezone when required.

    Parameters

    Returns ICalEvent

Methods

alarms

  • Get all alarms

    since

    0.2.0

    Returns ICalAlarm[]

  • Add one or multiple alarms

    const event = ical().createEvent();
    
    cal.alarms([
        {type: 'display', trigger: 600},
        {type: 'audio', trigger: 300}
    ]);
    
    cal.alarms(); // --> [ICalAlarm, ICalAlarm]
    
    since

    0.2.0

    Parameters

    Returns ICalEvent

allDay

  • allDay(): boolean
  • allDay(allDay: boolean): ICalEvent
  • Get the event's allDay flag

    since

    0.2.0

    Returns boolean

  • Set the event's allDay flag.

    event.allDay(true); // → appointment is for the whole day
    
    since

    0.2.0

    Parameters

    • allDay: boolean

    Returns ICalEvent

attendees

  • Get all attendees

    since

    0.2.0

    Returns ICalAttendee[]

  • Add multiple attendees to your event

    const event = ical().createEvent();
    
    cal.attendees([
        {email: 'a@example.com', name: 'Person A'},
        {email: 'b@example.com', name: 'Person B'}
    ]);
    
    cal.attendees(); // --> [ICalAttendee, ICalAttendee]
    
    since

    0.2.0

    Parameters

    Returns ICalEvent

busystatus

categories

  • Get all categories

    since

    0.3.0

    Returns ICalCategory[]

  • Add categories to the event or return all selected categories.

    const event = ical().createEvent();
    
    cal.categories([
        {name: 'APPOINTMENT'},
        {name: 'MEETING'}
    ]);
    
    cal.categories(); // --> [ICalCategory, ICalCategory]
    
    since

    0.3.0

    Parameters

    Returns ICalEvent

createAlarm

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

    const cal = ical();
    const event = cal.createEvent();
    const alarm = event.createAlarm({type: 'display', trigger: 300});
    
    // add another alarm
    event.createAlarm({
        type: 'audio',
        trigger: 300, // 5min before event
    });
    
    since

    0.2.1

    Parameters

    Returns ICalAlarm

createAttendee

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

    const cal = ical();
    const event = cal.createEvent();
    const attendee = event.createAttendee({email: 'hui@example.com', name: 'Hui'});
    
    // add another attendee
    event.createAttendee('Buh <buh@example.net>');
    

    As with the organizer, you can also add an explicit mailto address.

    event.createAttendee({email: 'hui@example.com', name: 'Hui', mailto: 'another@mailto.com'});
    
    // overwrite an attendee's mailto address
    attendee.mailto('another@mailto.net');
    
    since

    0.2.0

    Parameters

    Returns ICalAttendee

createCategory

  • Creates a new ICalCategory and returns it. Use options to prefill the categories' attributes. Calling this method without options will create an empty category.

    const cal = ical();
    const event = cal.createEvent();
    const category = event.createCategory({name: 'APPOINTMENT'});
    
    // add another alarm
    event.createCategory({
        name: 'MEETING'
    });
    
    since

    0.3.0

    Parameters

    Returns ICalCategory

created

description

  • Get the event's description as an ICalDescription object.

    since

    0.2.0

    Returns null | ICalDescription

  • Set the events description by passing a plaintext string or an object containing both a plaintext and a html description. Only a few calendar apps support html descriptions and like in emails, supported HTML tags and styling is limited.

    event.description({
        plain: 'Hello World!';
        html: '<p>Hello World!</p>';
    });
    
    since

    0.2.0

    Parameters

    Returns ICalEvent

end

  • Get the event end time which is currently set. Can be any supported date object.

    since

    0.2.0

    Returns null | ICalDateTimeValue

  • Set the appointment date of end. You can use any supported date object, see readme for details about supported values and timezone handling.

    since

    0.2.0

    Parameters

    Returns ICalEvent

floating

  • floating(): boolean
  • floating(floating: boolean): ICalEvent

id

  • id(): string
  • id(id: string | number): ICalEvent
  • Get the event's ID

    since

    0.2.0

    Returns string

  • Use this method to set the event's ID. If not set, a UUID will be generated randomly.

    Parameters

    • id: string | number

      Event ID you want to set

    Returns ICalEvent

lastModified

location

  • Get the event's location

    since

    0.2.0

    Returns null | ICalLocation

  • Set the event's location by passing a string (minimum) or an ICalLocation object which will also fill the iCal GEO attribute and Apple's X-APPLE-STRUCTURED-LOCATION.

    event.location({
       title: 'Apple Store Kurfürstendamm',
       address: 'Kurfürstendamm 26, 10719 Berlin, Deutschland',
       radius: 141.1751386318387,
       geo: {
           lat: 52.503630,
           lon: 13.328650
       }
    });
    
    since

    0.2.0

    Parameters

    Returns ICalEvent

organizer

  • Get the event's organizer

    since

    0.2.0

    Returns null | ICalOrganizer

  • Set the event's organizer

    event.organizer({
       name: 'Organizer\'s Name',
       email: 'organizer@example.com'
    });
    
    // OR
    
    event.organizer('Organizer\'s Name <organizer@example.com>');
    

    You can also add an explicit mailto email address.

        event.organizer({
       name: 'Organizer\'s Name',
       email: 'organizer@example.com',
       mailto: 'explicit@mailto.com'
    })
    
    since

    0.2.0

    Parameters

    Returns ICalEvent

priority

  • priority(): null | number
  • priority(priority: null | number): ICalEvent
  • Get the event's priority. A value of 1 represents the highest priority, 9 the lowest. 0 specifies an undefined priority.

    since

    v2.0.0-develop.7

    Returns null | number

  • Set the event's priority. A value of 1 represents the highest priority, 9 the lowest. 0 specifies an undefined priority.

    since

    v2.0.0-develop.7

    Parameters

    • priority: null | number

    Returns ICalEvent

recurrenceId

repeating

  • Get the event's repeating options

    since

    0.2.0

    Returns null | string | ICalEventInternalRepeatingData | default

  • Set the event's repeating options by passing an ICalRepeatingOptions object.

    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 and february,
       byMonthDay: [1, 15], // repeat only on the 1st and 15th
       bySetPos: 3, // repeat every 3rd sunday (will take the first element of the byDay array)
       exclude: [new Date('Dec 25 2013 00:00:00 UTC')], // exclude these dates
       excludeTimezone: 'Europe/Berlin', // timezone of exclude
       wkst: 'SU' // Start the week on Sunday, default is Monday
    });
    
    since

    0.2.0

    Parameters

    Returns ICalEvent

  • Set the event's repeating options by passing an RRule object.

    since

    2.0.0-develop.5

    Parameters

    • repeating: null | default

    Returns ICalEvent

  • Set the events repeating options by passing a string which is inserted in the ical file.

    since

    2.0.0-develop.5

    Parameters

    • repeating: null | string

    Returns ICalEvent

sequence

  • sequence(): number
  • sequence(sequence: number): ICalEvent
  • Get the event's SEQUENCE number. Use this method to get the event's revision sequence number of the calendar component within a sequence of revisions.

    since

    0.2.6

    Returns number

  • Set the event's SEQUENCE number. For a new event, this should be zero. Each time the organizer makes a significant revision, the sequence number should be incremented.

    Parameters

    • sequence: number

      Sequence number or null to unset it

    Returns ICalEvent

stamp

  • Get the event's timestamp

    since

    0.2.0

    Returns ICalDateTimeValue

  • Set the appointment date of creation. Defaults to the current time and date (new Date()). You can use any supported date object, see readme for details about supported values and timezone handling.

    since

    0.2.0

    Parameters

    Returns ICalEvent

start

  • Get the event start time which is currently set. Can be any supported date object.

    since

    0.2.0

    Returns null | ICalDateTimeValue

  • Set the appointment date of beginning, which is required for all events. You can use any supported date object, see Readme for details about supported values and timezone handling.

    since

    0.2.0

    Parameters

    Returns ICalEvent

status

summary

  • summary(): string
  • summary(summary: string): ICalEvent
  • Get the event's summary

    since

    0.2.0

    Returns string

  • Set the event's summary. Defaults to an empty string if nothing is set.

    since

    0.2.0

    Parameters

    • summary: string

    Returns ICalEvent

timestamp

  • Get the event's timestamp

    since

    0.2.0

    alias

    stamp

    Returns ICalDateTimeValue

  • Set the appointment date of creation. Defaults to the current time and date (new Date()). You can use any supported date object, see readme for details about supported values and timezone handling.

    since

    0.2.0

    alias

    stamp

    Parameters

    Returns ICalEvent

timezone

  • timezone(): null | string
  • timezone(timezone: null | string): ICalEvent
  • Get the event's timezone.

    since

    0.2.6

    Returns null | string

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

    See Readme for details about supported values and timezone handling.

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

    0.2.6

    Parameters

    • timezone: null | string

    Returns ICalEvent

toJSON

  • Return a shallow copy of the events'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 event = ical().createEvent();
    const json = JSON.stringify(event);
    
    // later: restore event data
    const calendar = ical().createEvent(JSON.parse(json));
    
    since

    0.2.4

    Returns ICalEventJSONData

toString

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

    const event = ical().createEvent();
    console.log(event.toString()); // → BEGIN:VEVENT…
    

    Returns string

transparency

  • Get the event's transparency

    since

    1.7.3

    Returns null | ICalEventTransparency

  • Set the event's transparency

    Set the field to OPAQUE if the person or resource is no longer available due to this event. If the calendar entry has no influence on availability, you can set the field to TRANSPARENT. This value is mostly used to find out if a person has time on a certain date or not (see TRANSP in iCal specification).

    import ical, {ICalEventTransparency} from 'ical-generator';
    event.transparency(ICalEventTransparency.OPAQUE);
    
    since

    1.7.3

    Parameters

    Returns ICalEvent

uid

  • uid(): string
  • uid(id: string | number): ICalEvent
  • Get the event's ID

    since

    0.2.0

    alias

    id

    Returns string

  • Use this method to set the event's ID. If not set, a UUID will be generated randomly.

    alias

    id

    Parameters

    • id: string | number

      Event ID you want to set

    Returns ICalEvent

url

  • url(): null | string
  • url(url: null | string): ICalEvent
  • Get the event's URL

    since

    0.2.0

    Returns null | string

  • Set the event's URL

    since

    0.2.0

    Parameters

    • url: null | string

    Returns ICalEvent

x

  • x(keyOrArray: [string, string][] | Record<string, string> | { key: string; value: string }[]): ICalEvent
  • x(keyOrArray: string, value: string): ICalEvent
  • x(): { key: string; value: string }[]
  • Set X-* attributes. Woun't filter double attributes, which are also added by another method (e.g. summary), so these attributes may be inserted twice.

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

    1.9.0

    Parameters

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

    Returns ICalEvent

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

    event.x("X-MY-CUSTOM-ATTR", "1337!");
    
    since

    1.9.0

    Parameters

    • keyOrArray: string
    • value: string

    Returns ICalEvent

  • Get all custom X-* attributes.

    since

    1.9.0

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

Legend

  • Constructor
  • Method
  • Property

Generated using TypeDoc