Skip to main content
This release is 0 versions behind 8.1.1 — the latest version of @sebbo2002/ical-generator. Jump to latest

@sebbo2002/ical-generator@8.1.1-develop.3
Built and signed on GitHub Actions

ical-generator is a small piece of code which generates ical calendar files

This package works with Node.js, Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers, Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
82%
Published
a week ago (8.1.1-develop.3)
class ICalAlarm

Usually you get an ICalAlarm object like this:

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

You can also use the ICalAlarm object directly:

import ical, {ICalAlarm} from 'ical-generator';
const alarm = new ICalAlarm();
event.alarms([alarm]);

Constructors

new
ICalAlarm(
event: ICalEvent,
)

Constructor of ICalAttendee. The event reference is required to query the calendar's timezone and summary when required.

Properties

private
readonly
data: ICalInternalAlarmData
private
readonly
event: ICalEvent

Methods

attach(): { uri: string; mime: string | null; } | null

Get Attachment

attach(attachment:
{ uri: string; mime?: string | null; }
| string
| null
): this

Set Alarm attachment. Used to set the alarm sound if alarm type is audio. Defaults to "Basso".

const cal = ical();
const event = cal.createEvent();

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

// OR

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

Get all attendees

Add multiple attendees to your event

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.

Get the alarm description. Used to set the alarm message if alarm type is display. If the alarm type is email, it's used to set the email body. Defaults to the event's summary.

description(description: string | null): this

Set the alarm description. Used to set the alarm message if alarm type is display. If the alarm type is email, it's used to set the email body. Defaults to the event's summary.

Get to which time alarm trigger relates to. Can be either START or END. If the value is START the alarm is triggerd relative to the event start time. If the value is END the alarm is triggerd relative to the event end time

relatesTo(relatesTo: ICalAlarmRelatesTo | null): this

Use this method to set to which time alarm trigger relates to. Works only if trigger is a number

const cal = ical();
const event = cal.createEvent();
const alarm = cal.createAlarm();

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

alarm.relatesTo('START'); // -> 10 minutes before event starts
alarm.relatesTo('END'); // -> 10 minutes before event ends

alarm.trigger(-600); // -> 10 minutes after event starts

alarm.relatesTo('START'); // -> 10 minutes after event starts
alarm.relatesTo('END'); // -> 10 minutes after event ends

Get Alarm Repetitions

repeat(repeat: ICalAlarmRepeatData | null): this

Set Alarm Repetitions. Use this to repeat the alarm.

const cal = ical();
const event = cal.createEvent();

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

Get the alarm summary. Used to set the email subject if alarm type is email. Defaults to the event's summary.

summary(summary: string | null): this

Set the alarm summary. Used to set the email subject if alarm type is display. Defaults to the event's summary.

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

Return generated event as a string.

const alarm = event.createAlarm();
console.log(alarm.toString()); // → BEGIN:VALARM…

Get the trigger time for the alarm. Can either be a date and time value (ICalDateTimeValue) or a number, which will represent the seconds between alarm and event start. The number is negative, if the alarm is triggered after the event started.

Use this method to set the alarm time.

const cal = ical();
const event = cal.createEvent();
const alarm = cal.createAlarm();

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

You can use any supported date object, see readme for details about supported values and timezone handling.

Get the trigger time for the alarm. Can either be a date and time value (ICalDateTimeValue) or a number, which will represent the seconds between alarm and event start. The number is negative, if the alarm is triggered before the event started.

Use this method to set the alarm time. Unlike trigger, this time the alarm takes place after the event has started.

const cal = ical();
const event = cal.createEvent();
const alarm = cal.createAlarm();

alarm.trigger(600); // -> 10 minutes after event starts

You can use any supported date object, see readme for details about supported values and timezone handling.

Get the trigger time for the alarm. Can either be a date and time value (ICalDateTimeValue) or a number, which will represent the seconds between alarm and event start. The number is negative, if the alarm is triggered after the event started.

Use this method to set the alarm time.

const cal = ical();
const event = cal.createEvent();
const alarm = cal.createAlarm();

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

You can use any supported date object, see readme for details about supported values and timezone handling.

type(type: ICalAlarmType): this

Get the alarm type

Set the alarm type. See ICalAlarmType for available status options.

x(keyOrArray:
{ key: string; value: string; }[]
| [string, string][]
| Record<string, string>
): this

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

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

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

alarm.x({
    "X-MY-CUSTOM-ATTR": "1337!"
});
x(
keyOrArray: string,
value: string,
): this

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

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

Get all custom X-* attributes.

Add Package

deno add jsr:@sebbo2002/ical-generator

Import symbol

import ICalAlarm from "@sebbo2002/ical-generator";

---- OR ----

Import directly with a jsr specifier

import ICalAlarm from "jsr:@sebbo2002/ical-generator";

Add Package

npx jsr add @sebbo2002/ical-generator

Import symbol

import ICalAlarm from "@sebbo2002/ical-generator";

Add Package

yarn dlx jsr add @sebbo2002/ical-generator

Import symbol

import ICalAlarm from "@sebbo2002/ical-generator";

Add Package

pnpm dlx jsr add @sebbo2002/ical-generator

Import symbol

import ICalAlarm from "@sebbo2002/ical-generator";

Add Package

bunx jsr add @sebbo2002/ical-generator

Import symbol

import ICalAlarm from "@sebbo2002/ical-generator";