forked from jens-maus/node-ical
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
25 lines (20 loc) · 758 Bytes
/
Copy pathexample.js
File metadata and controls
25 lines (20 loc) · 758 Bytes
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
/*
* Example: Fetching and printing events from a remote calendar URL
*
* Shows how to retrieve an ICS file over HTTP and iterate over the
* resulting VEVENT entries using the Promise-based API.
*/
import ical from 'node-ical';
const url = 'https://raw.githubusercontent.com/jens-maus/node-ical/master/test/fixtures/festival-multiday-rrule.ics';
const dateFormat = new Intl.DateTimeFormat('en-GB', {
dateStyle: 'long',
timeStyle: 'short',
});
const data = await ical.fromURL(url);
for (const ev of Object.values(data)) {
if (ev.type === 'VEVENT') {
const when = ev.start ? dateFormat.format(ev.start) : 'unknown time';
const where = ev.location ? ` in ${ev.location}` : '';
console.log(`${ev.summary}${where} — ${when}`);
}
}