-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathnode-ical.d.ts
More file actions
514 lines (469 loc) · 16.5 KB
/
node-ical.d.ts
File metadata and controls
514 lines (469 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
declare module 'node-ical' {
/**
* Compatibility wrapper returned by node-ical (RRULE results are Date-based).
* Mirrors the public surface of the internal RRuleCompatWrapper.
*/
export type RRule = {
options: Record<string, unknown> & {byweekday?: Array<string | number>};
between: (after: Date, before: Date, inclusive?: boolean) => Date[];
all: (iterator?: (date: Date, index: number) => boolean | void) => Date[];
before: (date: Date, inclusive?: boolean) => Date | undefined;
after: (date: Date, inclusive?: boolean) => Date | undefined;
toText: (locale?: string) => string;
toString: () => string;
};
/**
* Minimal Fetch options type (subset of RequestInit) to avoid requiring DOM lib.
*/
export type FetchOptions = {
method?: string;
/**
* Accept common header container shapes without depending on DOM lib types.
* - Plain object map
* - Any iterable of [key,value] tuples (covers Arrays and WHATWG Headers at runtime)
*/
headers?: Record<string, string> | Iterable<[string, string]>;
/** Request body (caller supplied) */
body?: unknown;
/** Additional fetch options (e.g. agent, redirect, follow, timeout, signal, etc.) */
[key: string]: unknown;
};
/**
* Methods (Sync)
*/
export type NodeICalSync = {
parseICS: (body: string) => CalendarResponse;
parseFile: (file: string) => CalendarResponse;
};
export const sync: NodeICalSync;
/**
* Methods (Async)
*/
export type NodeICalAsync = {
fromURL: ((url: string, callback: NodeIcalCallback) => void) & ((url: string, options: FetchOptions | NodeIcalCallback, callback?: NodeIcalCallback) => void) & ((url: string) => Promise<CalendarResponse>);
parseICS: ((body: string, callback: NodeIcalCallback) => void) & ((body: string) => Promise<CalendarResponse>);
parseFile: ((file: string, callback: NodeIcalCallback) => void) & ((file: string) => Promise<CalendarResponse>);
};
export const async: NodeICalAsync;
/**
* Methods (Autodetect)
*/
export function fromURL(url: string, callback: NodeIcalCallback): void;
export function fromURL(url: string, options: FetchOptions | NodeIcalCallback, callback?: NodeIcalCallback): void;
export function fromURL(url: string): Promise<CalendarResponse>;
export function parseICS(body: string, callback: NodeIcalCallback): void;
export function parseICS(body: string): CalendarResponse;
export function parseFile(file: string, callback: NodeIcalCallback): void;
export function parseFile(file: string): CalendarResponse;
/**
* Expand a recurring event into individual instances within a date range.
*
* @param event - The VEVENT component to expand
* @param options - Expansion options
* @param options.from - Start of date range (inclusive)
* @param options.to - End of date range (inclusive)
* @param options.includeOverrides - Whether to apply RECURRENCE-ID overrides (default: true)
* @param options.excludeExdates - Whether to exclude EXDATE dates (default: true)
* @param options.expandOngoing - Whether to include events that started before range but are still ongoing (default: false)
* @returns Array of event instances sorted by start date
*
* @example
* ```typescript
* const events = ical.sync.parseFile('calendar.ics');
* const event = Object.values(events).find(e => e.type === 'VEVENT' && e.rrule);
*
* const instances = ical.expandRecurringEvent(event, {
* from: new Date('2024-01-01'),
* to: new Date('2024-12-31')
* });
*
* instances.forEach(instance => {
* console.log(`${instance.summary}: ${instance.start} - ${instance.end}`);
* console.log(`Full-day: ${instance.isFullDay}, Recurring: ${instance.isRecurring}`);
* });
* ```
*/
export function expandRecurringEvent(
event: VEvent,
options: ExpandRecurringEventOptions,
): EventInstance[];
/**
* Options for expanding recurring events
*/
export type ExpandRecurringEventOptions = {
/** Start of date range (inclusive) */
from: Date;
/** End of date range (inclusive) */
to: Date;
/** Whether to apply RECURRENCE-ID overrides (default: true) */
includeOverrides?: boolean;
/** Whether to exclude EXDATE dates (default: true) */
excludeExdates?: boolean;
/** Whether to include events that started before range but are still ongoing (default: false) */
expandOngoing?: boolean;
};
/**
* An individual instance of a recurring or non-recurring event
*/
export type EventInstance = {
/** Start date/time of this instance */
start: DateWithTimeZone;
/** End date/time of this instance */
end: DateWithTimeZone;
/** Event summary/title - copied from event, may include params */
summary: ParameterValue;
/** Whether this is a full-day event (date-only, no time component) */
isFullDay: boolean;
/** Whether this instance came from a recurring rule */
isRecurring: boolean;
/** Whether this instance is a RECURRENCE-ID override of the base event */
isOverride: boolean;
/** The VEVENT object for this instance (base event or override) */
event: VEvent;
};
/**
* Response objects
*/
export type NodeIcalCallback = (error: any, data: CalendarResponse | undefined) => void;
/**
* Response from parsing an iCalendar file.
* Contains calendar components indexed by UID, plus an optional vcalendar object
* with VCALENDAR-level properties (e.g., WR-CALNAME, WR-TIMEZONE, method, version).
*/
export type CalendarResponse = {
/** VCALENDAR-level properties (calendar metadata) */
vcalendar?: VCalendar;
/** Calendar components (events, todos, etc.) indexed by UID */
[uid: string]: CalendarComponent | VCalendar | undefined;
};
export type CalendarComponent = VTimeZone | VEvent | VTodo | VJournal | VFreebusy | VCalendar;
export type VTimeZone = TimeZoneProps & TimeZoneDictionary;
type TimeZoneProps = {
type: 'VTIMEZONE';
tzid: string;
tzurl?: string;
} & BaseComponent;
type TimeZoneDictionary = Record<string, TimeZoneDef | undefined>;
/**
* Example :
* TRIGGER:-P15M
* TRIGGER;RELATED=END:P5M
* TRIGGER;VALUE=DATE-TIME:19980101T050000Z
*/
type Trigger = string;
/**
* https://www.kanzaki.com/docs/ical/valarm.html
*/
export type VAlarm = {
type: 'VALARM';
action: 'AUDIO' | 'DISPLAY' | 'EMAIL' | 'PROCEDURE';
trigger: Trigger;
description?: string;
/**
* https://www.kanzaki.com/docs/ical/repeat.html
*/
repeat?: number;
/**
* Time between repeated alarms (if repeat is set)
* DURATION:PT15M
*/
duration?: unknown;
/**
* Everything except DISPLAY
* https://www.kanzaki.com/docs/ical/attach.html
*/
attach: unknown;
/**
* For action = email
*/
summary?: string;
/**
* For action = email
*/
attendee?: Attendee;
} & BaseComponent;
/**
* Common properties shared by calendar components (VEVENT, VTODO, VJOURNAL)
* that support recurrence and scheduling.
*/
type CalendarComponentCommon = {
uid?: string;
dtstamp?: DateWithTimeZone;
sequence?: number;
summary?: ParameterValue;
description?: ParameterValue;
start?: DateWithTimeZone;
datetype?: DateType;
created?: DateWithTimeZone;
lastmodified?: DateWithTimeZone;
class?: Class;
url?: string;
organizer?: Organizer;
attendee?: Attendee[] | Attendee;
categories?: string[];
rrule?: RRule;
recurrenceid?: DateWithTimeZone;
exdate?: Record<string, DateWithTimeZone>;
};
export type VEvent = CalendarComponentCommon & {
type: 'VEVENT';
// RFC 5545 required fields (override optional from CalendarComponentCommon)
uid: string;
dtstamp: DateWithTimeZone;
start: DateWithTimeZone;
datetype: DateType;
summary: ParameterValue;
// VEvent-specific fields
method?: Method;
/** Event location – may include params (e.g., LANGUAGE, ALTREP) */
location?: ParameterValue;
end?: DateWithTimeZone;
transparency?: Transparency;
completion?: string;
geo?: any;
status?: VEventStatus;
/**
* Modified instances of recurring events (RECURRENCE-ID overrides).
* Uses dual-key approach for RFC 5545 compliance:
* - Date-only key (YYYY-MM-DD) for simple lookups
* - Full ISO timestamp key for DATE-TIME recurrence instances
* Both keys reference the same event object.
*
* @example
* // Access recurrence by date
* const override = event.recurrences?.['2024-07-15'];
* // Access recurrence by specific time
* const override = event.recurrences?.['2024-07-15T14:00:00.000Z'];
*/
recurrences?: Record<string, Omit<VEvent, 'recurrences'>>;
alarms?: VAlarm[];
} & BaseComponent;
/**
* Todo status values as defined in RFC 5545
*/
export type VTodoStatus = 'NEEDS-ACTION' | 'COMPLETED' | 'IN-PROCESS' | 'CANCELLED';
/**
* Journal status values as defined in RFC 5545
*/
export type VJournalStatus = 'DRAFT' | 'FINAL' | 'CANCELLED';
/**
* VTODO component representing a task or to-do item.
*
* @example
* const data = ical.parseICS(icsString);
* const todos = Object.values(data).filter(item => item.type === 'VTODO');
* todos.forEach(todo => {
* console.log(`Task: ${todo.summary}`);
* console.log(`Due: ${todo.due}`);
* console.log(`Completed: ${todo.completion}%`);
* });
*/
export type VTodo = CalendarComponentCommon & {
type: 'VTODO';
// RFC 5545 required fields (override optional from CalendarComponentCommon)
uid: string;
dtstamp: DateWithTimeZone;
// VTodo-specific fields
method?: Method;
/** Task location – may include params (e.g., LANGUAGE, ALTREP) */
location?: ParameterValue;
/** When this task is due */
due?: DateWithTimeZone;
/** When this task was completed */
completed?: DateWithTimeZone;
/** Percentage of task completion (0-100) */
completion?: string;
status?: VTodoStatus;
/** Task priority (0 = undefined, 1 = highest, 9 = lowest) */
priority?: number;
/**
* Modified instances of recurring todos (RECURRENCE-ID overrides).
* Uses dual-key approach (date and ISO timestamp).
*/
recurrences?: Record<string, Omit<VTodo, 'recurrences'>>;
alarms?: VAlarm[];
} & BaseComponent;
/**
* VJOURNAL component representing a journal entry or note.
*
* @example
* const data = ical.parseICS(icsString);
* const journals = Object.values(data).filter(item => item.type === 'VJOURNAL');
* journals.forEach(journal => {
* console.log(`Entry: ${journal.summary}`);
* console.log(`Description: ${journal.description}`);
* });
*/
export type VJournal = CalendarComponentCommon & {
type: 'VJOURNAL';
// RFC 5545 required fields (override optional from CalendarComponentCommon)
uid: string;
dtstamp: DateWithTimeZone;
// VJournal-specific fields
method?: Method;
status?: VJournalStatus;
/**
* Modified instances of recurring journals (RECURRENCE-ID overrides).
* Uses dual-key approach (date and ISO timestamp).
*/
recurrences?: Record<string, Omit<VJournal, 'recurrences'>>;
} & BaseComponent;
/**
* Free/busy time type as defined in RFC 5545
*/
export type FreebusyType = 'FREE' | 'BUSY' | 'BUSY-UNAVAILABLE' | 'BUSY-TENTATIVE';
/**
* Free/busy period with start and end times
*/
export type FreebusyPeriod = {
/** Free/busy period type */
type: FreebusyType;
/** Start time of the period */
start: DateWithTimeZone;
/** End time of the period */
end: DateWithTimeZone;
};
/**
* VFREEBUSY component representing free/busy time information.
* Used to publish or request free/busy time for calendar users.
*
* @example
* const data = ical.parseICS(icsString);
* const freebusy = Object.values(data).find(item => item.type === 'VFREEBUSY');
* if (freebusy) {
* console.log(`Free/busy for: ${freebusy.organizer}`);
* freebusy.freebusy?.forEach(period => {
* console.log(`${period.type}: ${period.start} - ${period.end}`);
* });
* }
*/
export type VFreebusy = {
type: 'VFREEBUSY';
method?: Method;
uid?: string;
/** Organizer of the free/busy time (optional, not always present) */
organizer?: Organizer;
/** Start of free/busy period */
start?: DateWithTimeZone;
/** End of free/busy period */
end?: DateWithTimeZone;
dtstamp?: DateWithTimeZone;
/** URL to access the free/busy information */
url?: string;
/** Array of free/busy time periods */
freebusy?: FreebusyPeriod[];
/** Attendee information */
attendee?: Attendee[] | Attendee;
} & BaseComponent;
/**
* VCALENDAR component containing calendar-level metadata.
* Accessible via data.vcalendar after parsing.
*
* Note: X-prefixed properties (e.g., X-WR-CALNAME) have the 'X-' prefix removed
* by node-ical, so X-WR-CALNAME becomes WR-CALNAME in the parsed output.
*
* @example
* const data = ical.parseICS(icsString);
* const calendarName = data.vcalendar?.['WR-CALNAME'];
* const timezone = data.vcalendar?.['WR-TIMEZONE'];
*/
export type VCalendar = {
type: 'VCALENDAR';
prodid?: string;
version?: string;
calscale?: 'GREGORIAN' | string;
method?: Method;
/** Calendar name (X-WR-CALNAME in ICS file) */
'WR-CALNAME'?: string;
/** Calendar description (X-WR-CALDESC in ICS file) */
'WR-CALDESC'?: string;
/** Default timezone (X-WR-TIMEZONE in ICS file) */
'WR-TIMEZONE'?: string;
};
export type BaseComponent = Record<string, unknown>;
export type TimeZoneDef = {
type: 'DAYLIGHT' | 'STANDARD';
params: any[];
tzoffsetfrom: string;
tzoffsetto: string;
tzname: string;
start: DateWithTimeZone;
dateType: DateType;
rrule: string;
rdate: string | string[];
};
/**
* A property value that may include iCalendar parameters.
*
* When an iCalendar property has parameters (e.g., `SUMMARY;LANGUAGE=de:Restmuell`),
* node-ical returns an object with `params` and `val`. Without parameters, it returns
* the plain value directly.
*
* @example
* // Without parameters: string
* event.summary // => "Meeting"
*
* // With parameters: object
* event.summary // => { params: { LANGUAGE: "de" }, val: "Besprechung" }
*
* // Safe access pattern:
* const title = typeof event.summary === 'string'
* ? event.summary
* : event.summary.val;
*/
export type ParameterValue<T = string, P = Record<string, string>> = T | {
/** The actual property value */
val: T;
/** ICalendar parameters (e.g., LANGUAGE, ENCODING) */
params: P;
};
export type Organizer = ParameterValue<string, {
/** Common Name - display name of the organizer */
CN?: string;
/** Directory entry reference */
DIR?: string;
/** Sent by delegate */
'SENT-BY'?: string;
/** Language for text values */
LANGUAGE?: string;
/** Schedule agent */
'SCHEDULE-AGENT'?: string;
/** Allow additional parameters from parseParameters() */
[key: string]: string | undefined;
}>;
export type Attendee = ParameterValue<string, {
/** Calendar user type */
CUTYPE?: AttendeeCUType;
/** Participation role */
ROLE?: AttendeeRole;
/** Participation status */
PARTSTAT?: AttendeePartStat;
/** RSVP expectation */
RSVP?: boolean;
/** Common Name - display name of attendee */
CN?: string;
/** Number of guests (non-standard) */
'X-NUM-GUESTS'?: number;
/** Delegated to */
'DELEGATED-TO'?: string;
/** Delegated from */
'DELEGATED-FROM'?: string;
/** Group membership */
MEMBER?: string;
/** Directory entry reference */
DIR?: string;
/** Language for text values */
LANGUAGE?: string;
/** Allow additional parameters from parseParameters() */
[key: string]: string | number | boolean | undefined;
}>;
export type AttendeeCUType = 'INDIVIDUAL' | 'UNKNOWN' | 'GROUP' | 'ROOM' | string;
export type AttendeeRole = 'CHAIR' | 'REQ-PARTICIPANT' | 'NON-PARTICIPANT' | string;
export type AttendeePartStat = 'NEEDS-ACTION' | 'ACCEPTED' | 'DECLINED' | 'TENTATIVE' | 'DELEGATED';
export type DateWithTimeZone = Date & {tz?: string; dateOnly?: true};
export type DateType = 'date-time' | 'date';
export type Transparency = 'TRANSPARENT' | 'OPAQUE';
export type Class = 'PUBLIC' | 'PRIVATE' | 'CONFIDENTIAL';
export type Method = 'PUBLISH' | 'REQUEST' | 'REPLY' | 'ADD' | 'CANCEL' | 'REFRESH' | 'COUNTER' | 'DECLINECOUNTER';
export type VEventStatus = 'TENTATIVE' | 'CONFIRMED' | 'CANCELLED';
}