94
ical.js
@@ -45,2 +45,13 @@ /**************** | ||
var addTZ = function(dt, name, params){ | ||
var p = parseParams(params); | ||
if (params && p){ | ||
dt[name].tz = p.TZID | ||
} | ||
return dt | ||
} | ||
var dateParam = function(name){ | ||
@@ -50,4 +61,4 @@ return function(val, params, curr){ | ||
// Store as string - worst case scenario | ||
storeParam(val, params, curr) | ||
storeParam(name)(val, undefined, curr) | ||
if (params && params[0] === "VALUE=DATE") { | ||
@@ -61,42 +72,37 @@ // Just Date | ||
comps[1], | ||
parseInt(comps[2])-1, | ||
parseInt(comps[2], 10)-1, | ||
comps[3] | ||
); | ||
} | ||
return addTZ(curr, name, params); | ||
} | ||
} | ||
} else { | ||
//typical RFC date-time format | ||
var comps = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(Z)?$/.exec(val); | ||
if (comps !== null) { | ||
if (comps[7] == 'Z'){ // GMT | ||
curr[name] = new Date(Date.UTC( | ||
comps[1], | ||
parseInt(comps[2])-1, | ||
comps[3], | ||
comps[4], | ||
comps[5], | ||
comps[6] | ||
)); | ||
} else { | ||
curr[name] = new Date( | ||
comps[1], | ||
parseInt(comps[2])-1, | ||
comps[3], | ||
comps[4], | ||
comps[5], | ||
comps[6] | ||
); | ||
} | ||
} | ||
//typical RFC date-time format | ||
var comps = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(Z)?$/.exec(val); | ||
if (comps !== null) { | ||
if (comps[7] == 'Z'){ // GMT | ||
curr[name] = new Date(Date.UTC( | ||
parseInt(comps[1], 10), | ||
parseInt(comps[2], 10)-1, | ||
parseInt(comps[3], 10), | ||
parseInt(comps[4], 10), | ||
parseInt(comps[5], 10), | ||
parseInt(comps[6], 10 ) | ||
)); | ||
// TODO add tz | ||
} else { | ||
curr[name] = new Date( | ||
parseInt(comps[1], 10), | ||
parseInt(comps[2], 10)-1, | ||
parseInt(comps[3], 10), | ||
parseInt(comps[4], 10), | ||
parseInt(comps[5], 10), | ||
parseInt(comps[6], 10) | ||
); | ||
} | ||
} | ||
var p = parseParams(params); | ||
if (params && p){ | ||
curr[name].tz = p.TZID | ||
} | ||
return curr | ||
return addTZ(curr, name, params) | ||
} | ||
@@ -127,2 +133,4 @@ } | ||
par[curr.uid] = curr | ||
else | ||
par[Math.random()*100000] = curr // Randomly assign ID : TODO - use true GUID | ||
} | ||
@@ -134,7 +142,6 @@ | ||
, 'UID' : storeParam('uid') | ||
, 'DESCRIPTION' : storeParam('description') | ||
, 'LOCATION' : storeParam('location') | ||
, 'DTSTART' : dateParam('start') | ||
, 'DTEND' : dateParam('end') | ||
,' CLASS' : storeParam('location') | ||
,' CLASS' : storeParam('class') | ||
, 'TRANSP' : storeParam('transparency') | ||
@@ -175,7 +182,6 @@ , 'GEO' : geoParam('geo') | ||
var value = kv.slice(1).join(":") | ||
, kp = kv[0].split(";") | ||
, name = kp[0] | ||
, params = kp.slice(1) | ||
var kp = kv[0].split(";") | ||
var name = kp[0] | ||
var params = kp.slice(1) | ||
ctx = exports.handleObject(name, value, params, ctx, out, l) || {} | ||
@@ -182,0 +188,0 @@ } |
{"name": "ical", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "index.js" | ||
@@ -12,2 +12,10 @@ ,"description": "A tolerant, minimal icalendar parser" | ||
} | ||
, "devDependencies": { | ||
"vows" : "0.6.1" | ||
, "underscore": "1.3.0" | ||
} | ||
, "scripts": { | ||
"test": "./node_modules/vows/bin/vows ./test/test.js" | ||
} | ||
} |
@@ -1,9 +0,34 @@ | ||
# node-ical # | ||
# ical.js # | ||
(Formerly node-ical) | ||
A tolerant, minimal icalendar parser | ||
[](http://travis-ci.org/peterbraden/node-ical) | ||
A tolerant, minimal icalendar parser for javascript/node | ||
(http://tools.ietf.org/html/rfc5545) | ||
## Install - Node.js ## | ||
ical.js is availble on npm: | ||
npm install ical | ||
## API ## | ||
ical.parseICS(str) | ||
Parses a string with an ICS File | ||
## Example 1 - Print list of upcoming node conferences (see example.js) | ||
var ical = require('ical') | ||
@@ -23,1 +48,3 @@ ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function(err, data) { | ||
@@ -18,6 +18,7 @@ /**** | ||
,'we get 8 events': function (topic) { | ||
,'we get 9 events': function (topic) { | ||
var events = _.select(_.values(topic), function(x){ return x.type==='VEVENT'}) | ||
assert.equal (events.length, 8); | ||
assert.equal (events.length, 9); | ||
} | ||
,'event 47f6e' : { | ||
@@ -56,2 +57,13 @@ topic: function(events){ | ||
} | ||
, 'event sdfkf09fsd0 (Invalid Date)' :{ | ||
topic : function(events){ | ||
return _.select(_.values(events), | ||
function(x){ | ||
return x.uid === 'sdfkf09fsd0'})[0] | ||
} | ||
, 'has a start datetime' : function(topic){ | ||
assert.equal(topic.start, "Next Year") | ||
} | ||
} | ||
} | ||
@@ -155,2 +167,17 @@ , 'with test2.ics (testing ical features)' : { | ||
, 'with test6.ics (testing assembly.org)' : { | ||
topic: function () { | ||
return ical.parseFile('./test/test6.ics') | ||
} | ||
, 'event with no ID' : { | ||
topic: function(events) { | ||
return _.select(_.values(events), function(x) { | ||
return x.summary === 'foobar Summer 2011 starts!'; | ||
})[0]; | ||
} | ||
, 'has a start' : function(topic){ | ||
assert.equal(topic.start.toISOString(), new Date(2011, 07, 04, 12, 0,0).toISOString()) | ||
} | ||
} | ||
} | ||
}).export(module) | ||
@@ -157,0 +184,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
93799
63.26%14
7.69%349
9.06%50
117.39%0
-100%2
Infinity%