-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathexample-typescript.ts
More file actions
46 lines (40 loc) · 1.36 KB
/
example-typescript.ts
File metadata and controls
46 lines (40 loc) · 1.36 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
// TypeScript usage example demonstrating VCALENDAR metadata access
import * as ical from 'node-ical';
// Example: Parse Google Calendar
const data = ical.sync.parseICS(`BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
X-WR-CALNAME:node-ical test
X-WR-TIMEZONE:Europe/Moscow
X-WR-CALDESC:A simple calendar to test node-ical parser
BEGIN:VEVENT
DTSTART:20240101T100000Z
DTEND:20240101T110000Z
SUMMARY:Test Event
UID:test-event-1
END:VEVENT
END:VCALENDAR`);
// Access VCALENDAR properties via vcalendar object
if (data.vcalendar) {
// TypeScript knows these properties exist!
const calendarName: string | undefined = data.vcalendar['WR-CALNAME'];
const timezone: string | undefined = data.vcalendar['WR-TIMEZONE'];
const description: string | undefined = data.vcalendar['WR-CALDESC'];
const {version} = data.vcalendar;
const {method} = data.vcalendar;
console.log('Calendar Name:', calendarName);
console.log('Timezone:', timezone);
console.log('Description:', description);
console.log('Version:', version);
console.log('Method:', method);
}
// Access events as before
for (const uid in data) {
if (!Object.hasOwn(data, uid)) {
continue;
}
const component = data[uid];
if (component && typeof component === 'object' && 'type' in component && component.type === 'VEVENT') {
console.log('Event:', component.summary);
}
}