forked from peterbraden/ical.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-ical.js
More file actions
31 lines (25 loc) · 792 Bytes
/
node-ical.js
File metadata and controls
31 lines (25 loc) · 792 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
26
27
28
29
30
31
var ical = require('./ical')
, request = require('request')
, fs = require('fs')
exports.fromURL = function(url, opts, cb){
if (!cb)
return;
request(url, opts, function(err, r, data){
if (err)
return cb(err, null);
cb(undefined, ical.parseICS(data));
})
}
exports.parseFile = function(filename){
return ical.parseICS(fs.readFileSync(filename, 'utf8'))
}
var rrule = require('rrule').RRule
ical.objectHandlers['RRULE'] = function(val, params, curr, stack, line){
var options = rrule.parseString(line.replace("RRULE:", ""));
// If not DTSTART was given with RRULE and DTSTART already set, use it
if (options.dtstart === undefined && curr.start !== undefined) {
options.dtstart = curr.start;
}
curr['rrule'] = new rrule(options);
return curr
}