Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

icalendar

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

icalendar - npm Package Compare versions

Comparing version 0.6.3 to 0.6.5

.npmignore

2

lib/icalendar.js

@@ -41,4 +41,4 @@ // Copyright (C) 2011 Tri Tech Computers Ltd.

if(!empty) {
this.addProperty('PRODID', require('./index').PRODID);
this.addProperty('VERSION', '2.0');
this.addProperty('PRODID', require('./index').PRODID);
}

@@ -45,0 +45,0 @@ }

@@ -89,2 +89,93 @@ // Copyright (C) 2011 Tri Tech Computers Ltd.

PROP_NAME = 0;
PARAM_NAME = 1;
PARAM_VALUE = 2;
MAYBE_QUOTED_PARAM = 3;
QUOTED_PARAM_VALUE = 4;
PARAM_OR_VALUE = 5;
PROP_VALUE = 6;
function parse_record(rec) {
var propname;
var params = {};
var state = PROP_NAME;
var lastpos = 0;
var current_param;
// Switch state and bookmark the current position
function newstate(s) {
state = s;
lastpos = i+1;
}
// Return the accumulated string since the last state change
function str() {
return rec.substr(lastpos, i - lastpos);
}
var i=0, j=rec.length;
for(; i<j; ++i) {
var ch = rec[i];
switch(state) {
case PROP_NAME:
if(ch == ':' || ch == ';') {
propname = str();
state = PARAM_OR_VALUE;
--i; // Re-evaluate
}
break;
case PARAM_OR_VALUE:
if(ch == ':')
newstate(PROP_VALUE);
else if(ch == ';')
newstate(PARAM_NAME);
else
throw new Error("Parse error");
break;
case PARAM_NAME:
if(ch == '=') {
current_param = str();
newstate(MAYBE_QUOTED_PARAM);
}
break;
case MAYBE_QUOTED_PARAM:
if(ch == '"')
newstate(QUOTED_PARAM_VALUE);
else
state = PARAM_VALUE;
break;
case PARAM_VALUE:
if(ch == ':' || ch == ';') {
params[current_param] = str();
state = PARAM_OR_VALUE;
--i; // Re-evaluate
}
break;
case QUOTED_PARAM_VALUE:
if(ch == '"') {
params[current_param] = str();
state = PARAM_OR_VALUE;
}
break;
case PROP_VALUE:
// Done...
i=j;
break;
default:
throw new Error("Invalid parser state");
}
}
return [ propname, str(), params ];
}
// Parse iCalendar formatted data and return an iCalendar object

@@ -114,2 +205,5 @@ //

continue;
if(state === undefined)
throw new ParseError("Mismatched BEGIN/END tags");

@@ -131,15 +225,3 @@ // Peek ahead to find line continuations...

var element = record.match(/^([^:]+):(.*)/);
var paramlist = element[1].split(';');
var propname = paramlist.shift();
var parameters = {};
for(var k=0; k<paramlist.length; ++k) {
var pval = paramlist[k].match(/^([^=]+)=(.*)/);
parameters[pval[1]] = pval[2];
}
if(state === undefined)
throw new ParseError("Mismatched BEGIN/END tags");
state = state(propname, element[2], parameters);
state = state.apply(null, parse_record(record));
}

@@ -146,0 +228,0 @@

@@ -56,3 +56,3 @@ // Copyright (C) 2011 Tri Tech Computers Ltd.

if(!this.getComponents('DAYLIGHT').length)
return this.getComponents('STANDARD').getPropertyValue('TZOFFSETTO');
return this.getComponents('STANDARD')[0].getPropertyValue('TZOFFSETTO');

@@ -63,5 +63,12 @@ // Right now we're only supporting a single element

var next_std = this.getRRule('STANDARD').next(dt);
var next_dst = this.getRRule('DAYLIGHT').next(dt);
var next_std = this.getRRule('STANDARD');
var next_dst = this.getRRule('DAYLIGHT');
if (next_std === null || next_dst === null) {
var comp = this.getComponents('STANDARD')[0];
return comp.getPropertyValue('TZOFFSETTO');
}
next_std = next_std.next(dt);
next_dst = next_dst.next(dt);
// TODO: Using prevOccurs would be a better solution

@@ -68,0 +75,0 @@ // If the NEXT DST/STD crossover after `dt` is DST,

@@ -102,4 +102,6 @@ // Copyright (C) 2011 Tri Tech Computers Ltd.

if(tz !== undefined) {
tz = calendar.timezone(tz);
return tz.fromLocalTime(d);
var tzobj = calendar.timezone(tz);
if(!tzobj)
throw new Error("Unable to load TZ data for "+tz);
return tzobj.fromLocalTime(d);
}

@@ -129,3 +131,3 @@

var dur = ['P'];
if(neg) dur.push('-');
if(neg) dur.unshift('-');
if(w) dur.push(w+'W');

@@ -140,10 +142,12 @@ if(d) dur.push(d+'D');

parse: function(value) {
var match = /P(\d+W)?(\d+D)?(?:T(\d+H)?(\d+M)?(\d+S)?)?/.exec(value).slice(1);
var mul = [ 60*60*24*7, 60*60*24, 60*60, 60, 1 ];
var match = /(-)?P(\d+W)?(\d+D)?(?:T(\d+H)?(\d+M)?(\d+S)?)?/.exec(value).slice(1);
var mul = [ -1, 60*60*24*7, 60*60*24, 60*60, 60, 1 ];
var dur = 0;
for(var i=0; i < match.length; ++i) {
for(var i=1; i < match.length; ++i) {
if(match[i] !== undefined) dur += parseInt(match[i], 10) * mul[i];
}
if(match[0] !== undefined) dur *= mul[0];
return dur;

@@ -150,0 +154,0 @@ }

{
"name": "icalendar",
"version": "0.6.3",
"version": "0.6.5",
"author": "James Emerton <james@tri-tech.com>",

@@ -17,2 +17,6 @@ "description": "RFC5545 iCalendar parser/generator",

},
"repository": {
"type": "git",
"url": "git://github.com/tritech/node-icalendar.git"
},
"dependencies": {},

@@ -25,2 +29,2 @@ "engines": {

}
}
}

@@ -16,4 +16,4 @@ // Test search

'BEGIN:VCALENDAR',
'VERSION:2.0',
'PRODID:'+icalendar.PRODID,
'VERSION:2.0',
'END:VCALENDAR'], ics.format());

@@ -46,4 +46,4 @@ });

'BEGIN:VCALENDAR\r\n'+
'VERSION:2.0\r\n'+
'PRODID:'+icalendar.PRODID+'\r\n'+
'VERSION:2.0\r\n'+
'BEGIN:VEVENT\r\n'+

@@ -112,4 +112,4 @@ 'DTSTAMP:'+dtstamp+'\r\n'+

'BEGIN:VCALENDAR\r\n'+
'VERSION:2.0\r\n'+
'PRODID:-//Bobs Software Emporium//NONSGML Bobs Calendar//EN\r\n'+
'VERSION:2.0\r\n'+
'BEGIN:VEVENT\r\n'+

@@ -116,0 +116,0 @@ 'DTSTAMP:20111202T165900\r\n'+

@@ -221,3 +221,20 @@ // Test search

});
it('parses quoted property parameter values', function() {
var cal = parse_calendar(
'BEGIN:VCALENDAR\r\n'+
'PRODID:-//Bobs Software Emporium//NONSGML Bobs Calendar//EN\r\n'+
'VERSION:2.0\r\n'+
'BEGIN:VEVENT\r\n'+
'DTSTAMP:20111202T165900\r\n'+
'X-TEST;TESTPARAM="Something;:, here":testvalue\r\n'+
'UID:testuid@someotherplace.com\r\n'+
'END:VEVENT\r\n'+
'END:VCALENDAR\r\n');
var vevent = cal.getComponents('VEVENT')[0];
assert.equal('Something;:, here',
vevent.getProperty('X-TEST').getParameter('TESTPARAM'));
});
});

@@ -28,2 +28,4 @@

assert.equal('-PT11M', icalendar.format_value('DURATION', -60*11));
assert.equal('1.333', icalendar.format_value('FLOAT', 1.333));

@@ -66,4 +68,2 @@ assert.equal('-3.14', icalendar.format_value('FLOAT', -3.14));

expect(icalendar.parse_value('CREATED', '20120814T175046Z')
toEqual(new Date(Date.UTC(2012,08,14,17,50,46)));
expect(icalendar.parse_value('DATE', '20111109'))

@@ -73,4 +73,2 @@ .toEqual(new Date(2011,10,9));

.toEqual(true);
expect(icalendar.parse_value('LAST-MODIFIED', '20120814T175050Z')
toEqual(new Date(Date.UTC(2012,08,14,17,50,50)));

@@ -97,2 +95,4 @@ assert.equal((new Date(0,0,0,17,32,16)).valueOf(),

.toEqual(1);
expect(icalendar.parse_value('DURATION', '-PT11M'))
.toEqual(-60*11);

@@ -99,0 +99,0 @@ expect(icalendar.parse_value('RECUR', 'FREQ=YEARLY;BYMONTH=11;BYDAY=1SU'))

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc