Comparing version 1.0.2 to 1.0.3
// Generated by CoffeeScript 1.4.0 | ||
var moment, timezones; | ||
var moment; | ||
moment = require('moment-timezone'); | ||
timezones = require('./timezones'); | ||
module.exports = function(Alarm) { | ||
@@ -22,4 +20,3 @@ var VAlarm, VCalendar, VTimezone, VTodo, _ref; | ||
Alarm.prototype.toIcal = function() { | ||
var startDate, timezone, vtodo, _ref1, _ref2, | ||
_this = this; | ||
var mappedAttendees, startDate, timezone, vtodo, _ref1, _ref2; | ||
timezone = 'GMT'; | ||
@@ -36,2 +33,3 @@ try { | ||
uid: this.id, | ||
stampDate: moment.tz(moment(), 'UTC'), | ||
summary: this.description | ||
@@ -42,24 +40,31 @@ }); | ||
action: 'DISPLAY', | ||
description: this.description | ||
description: this.description, | ||
trigger: 'PT0M' | ||
}); | ||
} | ||
if (((_ref2 = this.action) === 'EMAIL' || _ref2 === 'BOTH') && (this.getAttendeesEmail != null)) { | ||
this.getAttendeesEmail().forEach(function(email) { | ||
return vtodo.addAlarm({ | ||
action: 'EMAIL', | ||
description: ("" + _this.description + " ") + (_this.details || ''), | ||
attendee: "mailto:" + email, | ||
summary: _this.description | ||
}); | ||
mappedAttendees = this.getAttendeesEmail().map(function(email) { | ||
return "mailto:" + email; | ||
}); | ||
vtodo.addAlarm({ | ||
action: 'EMAIL', | ||
description: this.description, | ||
attendee: mappedAttendees, | ||
summary: this.description, | ||
trigger: 'PT0M' | ||
}); | ||
} | ||
return vtodo; | ||
}; | ||
Alarm.fromIcal = function(vtodo) { | ||
var actions, alarm, timezone, valarms; | ||
Alarm.fromIcal = function(vtodo, defaultCalendar) { | ||
var actions, alarm, timezone, todoModel, valarms; | ||
if (defaultCalendar == null) { | ||
defaultCalendar = 'my calendar'; | ||
} | ||
alarm = new Alarm(); | ||
if (vtodo.fields["UID"]) { | ||
alarm.id = vtodo.fields["UID"]; | ||
todoModel = vtodo.model; | ||
if (todoModel.uid != null) { | ||
alarm.id = todoModel.uid; | ||
} | ||
alarm.description = vtodo.fields["SUMMARY"] || vtodo.fields["DESCRIPTION"]; | ||
alarm.description = todoModel.summary || todoModel.description; | ||
if (!alarm.description) { | ||
@@ -70,10 +75,7 @@ console.log('No alarm.description from iCal.'); | ||
try { | ||
timezone = vtodo.fields['DTSTART-TZID']; | ||
if (!timezones[timezone]) { | ||
timezone = 'UTC'; | ||
} | ||
timezone = vtodo.timezone; | ||
if (timezone !== 'UTC') { | ||
alarm.trigg = moment.tz(vtodo.fields['DTSTART'], VAlarm.icalDTFormat, timezone).toISOString(); | ||
alarm.trigg = moment.tz(todoModel.startDate, timezone.toISOString()); | ||
} else { | ||
alarm.trigg = moment(vtodo.fields['DTSTART'], VAlarm.icalDTUTCFormat).toISOString(); | ||
alarm.trigg = moment.tz(todoModel.startDate, 'UTC'.toISOString()); | ||
} | ||
@@ -93,15 +95,10 @@ } catch (e) { | ||
actions = valarms.reduce(function(actions, valarm) { | ||
var action, _ref1; | ||
var action; | ||
if (actions['BOTH'] != null) { | ||
return actions; | ||
return 'BOTH'; | ||
} | ||
if (((_ref1 = valarm.fields['TRIGGER']) !== 'PT0M' && _ref1 !== '-PT0M' && _ref1 !== 'PT0S' && _ref1 !== '-PT0S' && _ref1 !== '-PT0H' && _ref1 !== '-PT0H')) { | ||
return actions; | ||
} | ||
action = valarm.fields['ACTION']; | ||
action = valarm.model.action; | ||
if (action === 'DISPLAY') { | ||
if (actions['EMAIL'] != null) { | ||
actions = { | ||
'BOTH': true | ||
}; | ||
return 'BOTH'; | ||
} else { | ||
@@ -113,5 +110,3 @@ actions[action] = true; | ||
if (actions['DISPLAY'] != null) { | ||
actions = { | ||
'BOTH': true | ||
}; | ||
return 'BOTH'; | ||
} else { | ||
@@ -128,9 +123,16 @@ actions[action] = true; | ||
} else { | ||
if (actions.length === 1) { | ||
actions = actions.shift(); | ||
} | ||
alarm.action = actions; | ||
} | ||
} | ||
alarm.tags = [defaultCalendar]; | ||
return alarm; | ||
}; | ||
return Alarm.extractAlarms = function(component) { | ||
return Alarm.extractAlarms = function(component, defaultCalendar) { | ||
var alarms; | ||
if (defaultCalendar == null) { | ||
defaultCalendar = 'my calendar'; | ||
} | ||
alarms = []; | ||
@@ -140,3 +142,3 @@ component.walk(function(component) { | ||
if (component.name === 'VTODO') { | ||
alarm = Alarm.fromIcal(component); | ||
alarm = Alarm.fromIcal(component, defaultCalendar); | ||
if (alarm != null) { | ||
@@ -143,0 +145,0 @@ return alarms.push(alarm); |
156
lib/event.js
// Generated by CoffeeScript 1.4.0 | ||
var RRule, moment, timezones; | ||
var RRule, moment; | ||
moment = require('moment-timezone'); | ||
timezones = require('./timezones'); | ||
RRule = require('rrule').RRule; | ||
@@ -14,3 +12,3 @@ | ||
Event.prototype.toIcal = function() { | ||
var allDay, event, timezone, _ref1, | ||
var allDay, attendees, event, rrule, timezone, _ref1, _ref2, | ||
_this = this; | ||
@@ -27,4 +25,9 @@ allDay = this.start.length === 10; | ||
} | ||
rrule = this.rrule != null ? RRule.parseString(this.rrule) : null; | ||
attendees = (_ref1 = this.attendees) != null ? _ref1.map(function(attendee) { | ||
return attendee.email; | ||
}) : void 0; | ||
try { | ||
event = new VEvent({ | ||
stampDate: moment.tz(moment(), 'UTC'), | ||
startDate: moment.tz(this.start, timezone), | ||
@@ -37,3 +40,4 @@ endDate: moment.tz(this.end, timezone), | ||
allDay: allDay, | ||
rrule: this.rrule, | ||
rrule: rrule, | ||
attendee: attendees, | ||
timezone: this.timezone | ||
@@ -46,22 +50,23 @@ }); | ||
} | ||
if ((_ref1 = this.alarms) != null) { | ||
_ref1.forEach(function(alarm) { | ||
var _ref2, _ref3; | ||
if ((_ref2 = alarm.action) === 'DISPLAY' || _ref2 === 'BOTH') { | ||
if ((_ref2 = this.alarms) != null) { | ||
_ref2.forEach(function(alarm) { | ||
var mappedAttendees, _ref3, _ref4; | ||
if ((_ref3 = alarm.action) === VAlarm.DISPLAY_ACTION || _ref3 === 'BOTH') { | ||
event.add(new VAlarm({ | ||
trigger: alarm.trigg, | ||
action: 'DISPLAY', | ||
action: VAlarm.DISPLAY_ACTION, | ||
description: _this.description | ||
})); | ||
} | ||
if (((_ref3 = alarm.action) === 'EMAIL' || _ref3 === 'BOTH') && (_this.getAlarmAttendeesEmail != null)) { | ||
return _this.getAlarmAttendeesEmail().forEach(function(email) { | ||
return event.add(new VAlarm({ | ||
trigger: alarm.trigg, | ||
action: 'EMAIL', | ||
description: ("" + _this.description + " ") + (_this.details || ''), | ||
attendee: "mailto:" + email, | ||
summary: _this.description | ||
})); | ||
if (((_ref4 = alarm.action) === VAlarm.EMAIL_ACTION || _ref4 === 'BOTH') && (_this.getAlarmAttendeesEmail != null)) { | ||
mappedAttendees = _this.getAlarmAttendeesEmail().map(function(email) { | ||
return "mailto:" + email; | ||
}); | ||
return event.add(new VAlarm({ | ||
trigger: alarm.trigg, | ||
action: VAlarm.EMAIL_ACTION, | ||
summary: _this.description, | ||
description: _this.details || '', | ||
attendee: mappedAttendees | ||
})); | ||
} | ||
@@ -72,63 +77,64 @@ }); | ||
}; | ||
Event.fromIcal = function(vevent) { | ||
var alarms, end, event, options, rruleStr, start, timezone; | ||
Event.fromIcal = function(vevent, defaultCalendar) { | ||
var alarms, defaultCozyStatus, end, event, model, start, timezone, _ref1; | ||
if (defaultCalendar == null) { | ||
defaultCalendar = 'my calendar'; | ||
} | ||
event = new Event(); | ||
event.description = vevent.fields["SUMMARY"] || vevent.fields["DESCRIPTION"]; | ||
if (!event.description) { | ||
console.log('No event.description from iCal.'); | ||
return void 0; | ||
model = vevent.model; | ||
timezone = model.timezone || 'UTC'; | ||
if (model.uid != null) { | ||
event.id = model.uid; | ||
} | ||
event.details = vevent.fields["DESCRIPTION"] || vevent.fields["SUMMARY"]; | ||
event.place = vevent.fields["LOCATION"]; | ||
rruleStr = vevent.fields["RRULE"]; | ||
event.rrule = vevent.fields["RRULE"]; | ||
try { | ||
if (vevent.fields['DTSTART-VALUE'] === 'DATE') { | ||
event.start = moment.tz(vevent.fields['DTSTART'], VEvent.icalDateFormat, 'GMT').format(Event.dateFormat); | ||
event.end = moment.tz(vevent.fields['DTEND'], VEvent.icalDateFormat, 'GMT').format(Event.dateFormat); | ||
event.description = model.summary || ''; | ||
event.details = model.description || ''; | ||
event.place = model.location; | ||
event.rrule = new RRule(model.rrule).toString(); | ||
defaultCozyStatus = 'INVITATION-NOT-SENT'; | ||
event.attendees = (_ref1 = model.attendees) != null ? _ref1.map(function(attendee, index) { | ||
var contactid, email, id, status, _ref2; | ||
status = ((_ref2 = attendee.details) != null ? _ref2.status : void 0) || defaultCozyStatus; | ||
if (status === 'NEEDS-ACTION') { | ||
status = defaultCozyStatus; | ||
} | ||
email = attendee.email; | ||
id = index + 1; | ||
contactid = null; | ||
return { | ||
id: id, | ||
email: email, | ||
contactid: contactid, | ||
status: status | ||
}; | ||
}) : void 0; | ||
if (model.allDay) { | ||
event.start = moment.tz(model.startDate, 'UTC'.format(Event.dateFormat)); | ||
event.end = moment.tz(model.endDate, 'UTC'.format(Event.dateFormat)); | ||
} else { | ||
if (timezone !== 'UTC') { | ||
start = moment.tz(model.startDate, timezone); | ||
end = moment.tz(model.endDate, timezone); | ||
} else { | ||
timezone = vevent.fields['DTSTART-TZID']; | ||
if (!timezones[timezone]) { | ||
timezone = 'UTC'; | ||
} | ||
if (timezone !== 'UTC') { | ||
start = moment.tz(vevent.fields['DTSTART'], VEvent.icalDTFormat, timezone); | ||
end = moment.tz(vevent.fields['DTEND'], VEvent.icalDTFormat, timezone); | ||
} else { | ||
start = moment.tz(vevent.fields['DTSTART'], VEvent.icalDTUTCFormat, 'UTC'); | ||
end = moment.tz(vevent.fields['DTEND'], VEvent.icalDTUTCFormat, 'UTC'); | ||
} | ||
if (vevent.fields['RRULE'] != null) { | ||
event.timezone = timezone; | ||
event.start = start.format(Event.ambiguousDTFormat); | ||
event.end = end.format(Event.ambiguousDTFormat); | ||
} else { | ||
event.start = start.toISOString(); | ||
event.end = end.toISOString(); | ||
} | ||
start = moment.tz(model.startDate, 'UTC'); | ||
end = moment.tz(model.endDate, 'UTC'); | ||
} | ||
} catch (e) { | ||
console.log('event.start and event.end are required from //\ | ||
iCal'); | ||
return void 0; | ||
} | ||
if (vevent.fields['RRULE'] != null) { | ||
try { | ||
options = RRule.parseString(vevent.fields["RRULE"]); | ||
event.rrule = RRule.optionsToString(options); | ||
} catch (e) { | ||
console.log("Fail RRULE parsing"); | ||
console.log(e); | ||
if (model.rrule != null) { | ||
event.timezone = timezone; | ||
event.start = start.format(Event.ambiguousDTFormat); | ||
event.end = end.format(Event.ambiguousDTFormat); | ||
} else { | ||
event.start = start.toISOString(); | ||
event.end = end.toISOString(); | ||
} | ||
} | ||
alarms = []; | ||
vevent.subComponents.forEach(function(c) { | ||
var action, isEmailAction, trigg; | ||
if (c.name === !'VALARM') { | ||
vevent.subComponents.forEach(function(component) { | ||
var action, alarmModel, trigg; | ||
if (component.name === !'VALARM') { | ||
return; | ||
} | ||
trigg = c.fields['TRIGGER']; | ||
action = c.fields['ACTION']; | ||
isEmailAction = action === 'EMAIL' || action === 'DISPLAY'; | ||
if (trigg && trigg.match(Event.alarmTriggRegex) && isEmailAction) { | ||
alarmModel = component.model; | ||
trigg = alarmModel.trigger; | ||
action = alarmModel.action; | ||
if (trigg && trigg.match(Event.alarmTriggRegex)) { | ||
return alarms.push({ | ||
@@ -143,10 +149,14 @@ trigg: trigg, | ||
} | ||
event.tags = [defaultCalendar]; | ||
return event; | ||
}; | ||
return Event.extractEvents = function(component) { | ||
return Event.extractEvents = function(component, defaultCalendar) { | ||
var events; | ||
if (defaultCalendar == null) { | ||
defaultCalendar = 'my calendar'; | ||
} | ||
events = []; | ||
component.walk(function(component) { | ||
if (component.name === 'VEVENT') { | ||
return events.push(Event.fromIcal(component)); | ||
return events.push(Event.fromIcal(component, defaultCalendar)); | ||
} | ||
@@ -153,0 +163,0 @@ }); |
704
lib/index.js
// Generated by CoffeeScript 1.4.0 | ||
var ICalParser, VAlarm, VCalendar, VComponent, VDaylight, VEvent, VFreeBusy, VJournal, VStandard, VTimezone, VTodo, fs, iCalBuffer, lazy, moment, | ||
var FieldConflictError, FieldDependencyError, ICalParser, InvalidValueError, MissingFieldError, RRule, VALID_TZ_LIST, VAlarm, VCalendar, VComponent, VDaylight, VEvent, VFreeBusy, VJournal, VStandard, VTimezone, VTodo, extend, fs, helpers, iCalBuffer, lazy, moment, uuid, _ref, | ||
__hasProp = {}.hasOwnProperty, | ||
@@ -14,2 +14,14 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
extend = require('extend'); | ||
uuid = require('uuid'); | ||
RRule = require('rrule').RRule; | ||
VALID_TZ_LIST = moment.tz.names(); | ||
_ref = require('./errors'), MissingFieldError = _ref.MissingFieldError, FieldConflictError = _ref.FieldConflictError, FieldDependencyError = _ref.FieldDependencyError, InvalidValueError = _ref.InvalidValueError; | ||
helpers = require('./helpers'); | ||
module.exports.decorateAlarm = require('./alarm'); | ||
@@ -71,22 +83,55 @@ | ||
function VComponent() { | ||
function VComponent(options) { | ||
this.model = extend(true, {}, options); | ||
this.subComponents = []; | ||
this.fields = {}; | ||
this.rawFields = []; | ||
if (options != null) { | ||
this.validate(); | ||
this.build(); | ||
} | ||
} | ||
VComponent.prototype.validate = function() {}; | ||
VComponent.prototype.build = function() { | ||
return this.rawFields = []; | ||
}; | ||
VComponent.prototype.extract = function() { | ||
return this.model = {}; | ||
}; | ||
VComponent.prototype.toString = function() { | ||
var att, buf, component, val, _i, _len, _ref, _ref1; | ||
var buf; | ||
buf = new iCalBuffer; | ||
buf.addLine("BEGIN:" + this.name); | ||
_ref = this.fields; | ||
for (att in _ref) { | ||
val = _ref[att]; | ||
buf.addLine("" + att + ":" + val); | ||
this._toStringFields(buf); | ||
this._toStringComponents(buf); | ||
return buf.addString("END:" + this.name); | ||
}; | ||
VComponent.prototype._toStringFields = function(buf) { | ||
var field, _i, _len, _ref1, _results; | ||
_ref1 = this.rawFields; | ||
_results = []; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
field = _ref1[_i]; | ||
if (field.value != null) { | ||
_results.push(buf.addLine("" + field.key + ":" + field.value)); | ||
} else { | ||
_results.push(void 0); | ||
} | ||
} | ||
return _results; | ||
}; | ||
VComponent.prototype._toStringComponents = function(buf) { | ||
var component, _i, _len, _ref1, _results; | ||
_ref1 = this.subComponents; | ||
_results = []; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
component = _ref1[_i]; | ||
buf.addLine(component.toString()); | ||
_results.push(buf.addLine(component.toString())); | ||
} | ||
return buf.addString("END:" + this.name); | ||
return _results; | ||
}; | ||
@@ -101,8 +146,8 @@ | ||
VComponent.prototype.walk = function(walker) { | ||
var sub, _i, _len, _ref, _results; | ||
var sub, _i, _len, _ref1, _results; | ||
walker(this); | ||
_ref = this.subComponents; | ||
_ref1 = this.subComponents; | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
sub = _ref[_i]; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
sub = _ref1[_i]; | ||
_results.push(sub.walk(walker)); | ||
@@ -113,2 +158,35 @@ } | ||
VComponent.prototype.addRawField = function(key, value, details) { | ||
if (details == null) { | ||
details = {}; | ||
} | ||
return this.rawFields.push({ | ||
key: key, | ||
value: value, | ||
details: details | ||
}); | ||
}; | ||
VComponent.prototype.getRawField = function(key, findMany) { | ||
var defaultResult, field, _i, _len, _ref1; | ||
if (findMany == null) { | ||
findMany = false; | ||
} | ||
defaultResult = findMany ? [] : null; | ||
_ref1 = this.rawFields; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
field = _ref1[_i]; | ||
if (field.key === key) { | ||
if (findMany) { | ||
defaultResult.push(field); | ||
} else { | ||
if (field.key) { | ||
return field; | ||
} | ||
} | ||
} | ||
} | ||
return defaultResult; | ||
}; | ||
return VComponent; | ||
@@ -126,12 +204,40 @@ | ||
VCalendar.__super__.constructor.apply(this, arguments); | ||
if (!options) { | ||
return this; | ||
} | ||
this.fields = { | ||
VERSION: "2.0" | ||
}; | ||
this.fields['PRODID'] = "-//" + options.organization + "//NONSGML " + options.title + "//EN"; | ||
this.vtimezones = {}; | ||
} | ||
VCalendar.prototype.validate = function() { | ||
if (this.model.organization == null) { | ||
throw new MissingFieldError('organization'); | ||
} | ||
if (this.model.title == null) { | ||
throw new MissingFieldError('title'); | ||
} | ||
}; | ||
VCalendar.prototype.build = function() { | ||
var prodid; | ||
VCalendar.__super__.build.call(this); | ||
prodid = "-//" + this.model.organization + "//NONSGML " + this.model.title + "//EN"; | ||
this.addRawField('VERSION', '2.0'); | ||
return this.addRawField('PRODID', prodid); | ||
}; | ||
VCalendar.prototype.extract = function() { | ||
var extractPRODID, organization, results, title, value, _; | ||
VCalendar.__super__.extract.call(this); | ||
value = this.getRawField('PRODID').value; | ||
extractPRODID = /-\/\/([\w. ]+)\/\/?(?:NONSGML )?(.+)\/\/.*/; | ||
results = value.match(extractPRODID); | ||
if (results != null) { | ||
_ = results[0], organization = results[1], title = results[2]; | ||
} else { | ||
organization = 'Undefined organization'; | ||
title = 'Undefined title'; | ||
} | ||
return this.model = { | ||
organization: organization, | ||
title: title | ||
}; | ||
}; | ||
VCalendar.prototype.addTimezone = function(timezone) { | ||
@@ -144,10 +250,6 @@ if (!(this.vtimezones[timezone] != null)) { | ||
VCalendar.prototype.toString = function() { | ||
var att, buf, component, val, vtimezone, _, _i, _len, _ref, _ref1, _ref2; | ||
var buf, vtimezone, _, _ref1; | ||
buf = new iCalBuffer; | ||
buf.addLine("BEGIN:" + this.name); | ||
_ref = this.fields; | ||
for (att in _ref) { | ||
val = _ref[att]; | ||
buf.addLine("" + att + ":" + val); | ||
} | ||
this._toStringFields(buf); | ||
_ref1 = this.vtimezones; | ||
@@ -158,7 +260,3 @@ for (_ in _ref1) { | ||
} | ||
_ref2 = this.subComponents; | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
component = _ref2[_i]; | ||
buf.addLine(component.toString()); | ||
} | ||
this._toStringComponents(buf); | ||
return buf.addString("END:" + this.name); | ||
@@ -175,22 +273,138 @@ }; | ||
function VAlarm() { | ||
return VAlarm.__super__.constructor.apply(this, arguments); | ||
} | ||
VAlarm.prototype.name = 'VALARM'; | ||
function VAlarm(options) { | ||
VAlarm.__super__.constructor.apply(this, arguments); | ||
if (!options) { | ||
return this; | ||
VAlarm.EMAIL_ACTION = 'EMAIL'; | ||
VAlarm.DISPLAY_ACTION = 'DISPLAY'; | ||
VAlarm.AUDIO_ACTION = 'AUDIO'; | ||
VAlarm.prototype.validate = function() { | ||
var expected; | ||
if (this.model.action == null) { | ||
throw new MissingFieldError('action'); | ||
} | ||
this.fields = { | ||
ACTION: options.action, | ||
TRIGGER: options.trigger | ||
}; | ||
if (options.description != null) { | ||
this.fields.DESCRIPTION = options.description; | ||
if (this.model.trigger == null) { | ||
throw new MissingFieldError('trigger'); | ||
} | ||
if (options.action === 'EMAIL') { | ||
this.fields.ATTENDEE = options.attendee; | ||
this.fields.SUMMARY = options.summary; | ||
if ((this.model.duration != null) && !(this.model.repeat != null)) { | ||
throw new FieldDependencyError('duration', 'repeat'); | ||
} else if (!(this.model.duration != null) && (this.model.repeat != null)) { | ||
throw new FieldDependencyError('repeat', 'duration'); | ||
} | ||
} | ||
if (this.model.action === VAlarm.DISPLAY_ACTION) { | ||
if (this.model.description == null) { | ||
throw new MissingFieldError('description'); | ||
} | ||
} else if (this.model.action === VAlarm.EMAIL_ACTION) { | ||
if (this.model.description == null) { | ||
throw new MissingFieldError('description'); | ||
} | ||
if (this.model.summary == null) { | ||
throw new MissingFieldError('summary'); | ||
} | ||
if (this.model.attendees == null) { | ||
throw new MissingFieldError('attendees'); | ||
} | ||
} else if (this.model.action === VAlarm.AUDIO_ACTION) { | ||
} else { | ||
expected = [VAlarm.DISPLAY_ACTION, VAlarm.EMAIL_ACTION, VAlarm.AUDIO_ACTION]; | ||
throw new InvalidValueError('action', this.model.action, expected); | ||
} | ||
}; | ||
VAlarm.prototype.build = function() { | ||
var attendee, details, fieldValue, name, status, _i, _len, _ref1, _ref2, _ref3; | ||
VAlarm.__super__.build.call(this); | ||
this.addRawField('ACTION', this.model.action); | ||
this.addRawField('TRIGGER', this.model.trigger); | ||
if (this.model.attendees) { | ||
_ref1 = this.model.attendees; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
attendee = _ref1[_i]; | ||
status = ((_ref2 = attendee.details) != null ? _ref2.status : void 0) || 'NEEDS-ACTION'; | ||
details = ";PARTSTAT=" + status; | ||
name = ((_ref3 = attendee.details) != null ? _ref3.name : void 0) || attendee.email; | ||
details += ";CN=" + name; | ||
fieldValue = "mailto:" + attendee.email; | ||
this.addRawField("ATTENDEE" + details, fieldValue, details); | ||
} | ||
} | ||
this.addRawField('DESCRIPTION', this.model.description); | ||
this.addRawField('DURATION', this.model.duration || null); | ||
this.addRawField('REPEAT', this.model.repeat || null); | ||
return this.addRawField('SUMMARY', this.model.summary); | ||
}; | ||
VAlarm.prototype.extract = function() { | ||
var action, attendees, description, expected, summary, trigger, _ref1, _ref10, _ref11, _ref12, _ref13, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9; | ||
VAlarm.__super__.extract.call(this); | ||
trigger = ((_ref1 = this.getRawField('TRIGGER')) != null ? _ref1.value : void 0) || null; | ||
description = (_ref2 = this.getRawField('DESCRIPTION')) != null ? _ref2.value : void 0; | ||
attendees = this.getRawField('ATTENDEE', true); | ||
attendees = attendees != null ? attendees.map(function(attendee) { | ||
var detail, details, key, name, status, _i, _len, _ref3, _ref4, _ref5, _ref6; | ||
return attendee.value.replace('mailto:', ''); | ||
if (((_ref3 = attendee.details) != null ? _ref3.length : void 0) > 0) { | ||
details = {}; | ||
_ref4 = attendee.details; | ||
for (_i = 0, _len = _ref4.length; _i < _len; _i++) { | ||
detail = _ref4[_i]; | ||
if (detail.indexOf('PARTSTAT') !== -1) { | ||
_ref5 = detail.split('='), key = _ref5[0], status = _ref5[1]; | ||
details.status = status; | ||
} else if (detail.indexOf('CN') !== -1) { | ||
_ref6 = detail.split('='), key = _ref6[0], name = _ref6[1]; | ||
details.name = name; | ||
} | ||
} | ||
} else { | ||
details = { | ||
status: 'NEEDS-ACTION', | ||
name: email | ||
}; | ||
} | ||
return { | ||
email: email, | ||
details: details | ||
}; | ||
}) : void 0; | ||
summary = (_ref3 = this.getRawField('SUMMARY')) != null ? _ref3.value : void 0; | ||
expected = [VAlarm.DISPLAY_ACTION, VAlarm.EMAIL_ACTION, VAlarm.AUDIO_ACTION]; | ||
action = (_ref4 = this.getRawField('ACTION')) != null ? _ref4.value : void 0; | ||
if (__indexOf.call(expected, action) < 0) { | ||
action = VAlarm.DISPLAY_ACTION; | ||
if (description == null) { | ||
description = ((_ref5 = this.parent) != null ? (_ref6 = _ref5.getRawField('SUMMARY')) != null ? _ref6.value : void 0 : void 0) || ''; | ||
} | ||
} else if (action === VAlarm.DISPLAY_ACTION) { | ||
if (description == null) { | ||
description = ((_ref7 = this.parent) != null ? (_ref8 = _ref7.getRawField('SUMMARY')) != null ? _ref8.value : void 0 : void 0) || ''; | ||
} | ||
} else if (action === VAlarm.EMAIL_ACTION) { | ||
if (this.model.description == null) { | ||
description = ((_ref9 = this.parent) != null ? (_ref10 = _ref9.getRawField('DESCRIPTION')) != null ? _ref10.value : void 0 : void 0) || ''; | ||
} | ||
if (this.model.summary == null) { | ||
summary = ((_ref11 = this.parent) != null ? (_ref12 = _ref11.getRawField('SUMMARY')) != null ? _ref12.value : void 0 : void 0) || ''; | ||
} | ||
if (this.model.attendees == null) { | ||
attendees = []; | ||
} | ||
} | ||
return this.model = { | ||
action: action, | ||
trigger: trigger, | ||
attendees: attendees, | ||
description: description, | ||
repeat: ((_ref13 = this.getRawField('REPEAT')) != null ? _ref13.value : void 0) || null, | ||
summary: summary | ||
}; | ||
}; | ||
return VAlarm; | ||
@@ -204,23 +418,77 @@ | ||
function VTodo() { | ||
return VTodo.__super__.constructor.apply(this, arguments); | ||
} | ||
VTodo.prototype.name = 'VTODO'; | ||
function VTodo(options) { | ||
var startDate; | ||
VTodo.__super__.constructor.apply(this, arguments); | ||
if (options) { | ||
startDate = moment(options.startDate); | ||
this.fields = { | ||
DTSTART: startDate.format(VTodo.icalDTUTCFormat), | ||
SUMMARY: options.summary, | ||
DURATION: 'PT30M', | ||
UID: options.uid | ||
}; | ||
if (options.description != null) { | ||
this.fields.DESCRIPTION = options.description; | ||
VTodo.prototype.validate = function() { | ||
if (this.model.uid == null) { | ||
throw new MissingFieldError('uid'); | ||
} | ||
if (this.model.stampDate == null) { | ||
throw new MissingFieldError('stampDate'); | ||
} | ||
if ((this.model.due != null) && (this.model.duration != null)) { | ||
throw new FieldConflictError('due', 'duration'); | ||
} | ||
if ((this.model.duration != null) && !(this.model.startDate != null)) { | ||
throw new FieldDependencyError('startDate', 'duration'); | ||
} | ||
}; | ||
VTodo.prototype.build = function() { | ||
var formattedStartDate, stampDate, startDate; | ||
VTodo.__super__.build.call(this); | ||
stampDate = moment(this.model.stampDate); | ||
this.addRawField('UID', this.model.uid); | ||
this.addRawField('DTSTAMP', stampDate.format(VEvent.icalDTUTCFormat)); | ||
if (this.model.startDate != null) { | ||
startDate = moment(this.model.startDate); | ||
formattedStartDate = startDate.format(VTodo.icalDTUTCFormat); | ||
} | ||
this.addRawField('DESCRIPTION', this.model.description || null); | ||
this.addRawField('DTSTART', formattedStartDate || null); | ||
this.addRawField('DUE', this.model.due || null); | ||
this.addRawField('DURATION', this.model.duration || null); | ||
return this.addRawField('SUMMARY', this.model.summary || null); | ||
}; | ||
VTodo.prototype.extract = function() { | ||
var details, due, duration, stampDate, startDate, timezone, _, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8; | ||
VTodo.__super__.extract.call(this); | ||
stampDate = ((_ref1 = this.getRawField('DTSTAMP')) != null ? _ref1.value : void 0) || moment(); | ||
startDate = (_ref2 = this.getRawField('DTSTART')) != null ? _ref2.value : void 0; | ||
due = (_ref3 = this.getRawField('DUE')) != null ? _ref3.value : void 0; | ||
duration = (_ref4 = this.getRawField('DURATION')) != null ? _ref4.value : void 0; | ||
if ((due != null) && (duration != null)) { | ||
duration = null; | ||
} | ||
if (startDate != null) { | ||
details = this.getRawField('DTSTART').details; | ||
if (details.length > 0) { | ||
_ref5 = details[0].split('='), _ = _ref5[0], timezone = _ref5[1]; | ||
if (__indexOf.call(VALID_TZ_LIST, timezone) < 0) { | ||
timezone = 'UTC'; | ||
} | ||
} else { | ||
timezone = 'UTC'; | ||
} | ||
startDate = moment.tz(startDate, VTodo.icalDTUTCFormat, timezone); | ||
} else if (!(startDate != null) && (duration != null)) { | ||
startDate = moment.tz(moment(), 'UTC'); | ||
} | ||
} | ||
return this.model = { | ||
uid: ((_ref6 = this.getRawField('UID')) != null ? _ref6.value : void 0) || uuid.v1(), | ||
stampDate: moment(stampDate).toDate(), | ||
description: ((_ref7 = this.getRawField('DESCRIPTION')) != null ? _ref7.value : void 0) || '', | ||
startDate: startDate.toDate(), | ||
due: due, | ||
duration: duration, | ||
summary: ((_ref8 = this.getRawField('SUMMARY')) != null ? _ref8.value : void 0) || '', | ||
timezone: timezone | ||
}; | ||
}; | ||
VTodo.prototype.addAlarm = function(options) { | ||
options.trigger = 'PT0M'; | ||
return this.add(new VAlarm(options)); | ||
@@ -237,62 +505,203 @@ }; | ||
function VEvent() { | ||
return VEvent.__super__.constructor.apply(this, arguments); | ||
} | ||
VEvent.prototype.name = 'VEVENT'; | ||
function VEvent(options) { | ||
var fieldE, fieldS, formatE, formatS, rrule, tzE, tzS; | ||
VEvent.__super__.constructor.apply(this, arguments); | ||
if (options) { | ||
this.fields = { | ||
SUMMARY: options.summary, | ||
LOCATION: options.location, | ||
UID: options.uid | ||
}; | ||
if (options.description != null) { | ||
this.fields.DESCRIPTION = options.description; | ||
} | ||
fieldS = 'DTSTART'; | ||
fieldE = 'DTEND'; | ||
formatS = null; | ||
formatE = null; | ||
tzS = null; | ||
tzE = null; | ||
if (options.allDay) { | ||
fieldS += ";VALUE=DATE"; | ||
fieldE += ";VALUE=DATE"; | ||
formatS = formatE = VEvent.icalDateFormat; | ||
} else if (options.rrule) { | ||
formatS = formatE = VEvent.icalDTFormat; | ||
tzS = tzE = options.timezone; | ||
rrule = options.rrule.split(';'.filter(function(s) { | ||
return s.indexOf('DTSTART') !== 0..join(';'); | ||
})); | ||
this.fields['RRULE'] = rrule; | ||
VEvent.prototype.validate = function() { | ||
if (this.model.uid == null) { | ||
throw new MissingFieldError('uid'); | ||
} | ||
if (this.model.stampDate == null) { | ||
throw new MissingFieldError('stampDate'); | ||
} | ||
if (this.model.startDate == null) { | ||
throw new MissingFieldError('startDate'); | ||
} | ||
if ((this.model.endDate != null) && (this.model.duration != null)) { | ||
throw new FieldConflictError('endDate', 'duration'); | ||
} | ||
}; | ||
VEvent.prototype.build = function() { | ||
var attendee, details, fieldEnd, fieldStart, formatEnd, formatStart, name, rrule, stampDate, status, timezoneEnd, timezoneStart, _i, _len, _ref1, _ref2, _ref3; | ||
VEvent.__super__.build.call(this); | ||
if (!(this.model.endDate != null) && !(this.model.duration != null) && !(this.model.rrule != null)) { | ||
this.model.endDate = moment(this.model.startDate).add(1, 'd').toDate(); | ||
} | ||
fieldStart = "DTSTART"; | ||
fieldEnd = "DTEND"; | ||
formatStart = null; | ||
formatEnd = null; | ||
timezoneStart = null; | ||
timezoneEnd = null; | ||
if (this.model.allDay) { | ||
fieldStart += ";VALUE=DATE"; | ||
fieldEnd += ";VALUE=DATE"; | ||
formatStart = formatEnd = VEvent.icalDateFormat; | ||
} else if (this.model.rrule != null) { | ||
formatStart = formatEnd = VEvent.icalDTFormat; | ||
timezoneStart = timezoneEnd = this.model.timezone; | ||
} else { | ||
if (this.model.timezone) { | ||
formatStart = formatEnd = VEvent.icalDTFormat; | ||
timezoneStart = timezoneEnd = this.model.timezone; | ||
} else { | ||
if (options.timezone) { | ||
formatS = formatE = VEvent.icalDTFormat; | ||
tzS = tzE = options.timezone; | ||
if (this.model.startDate.getTimezone != null) { | ||
formatStart = VEvent.icalDTFormat; | ||
timezoneStart = this.model.startDate.getTimezone(); | ||
} else { | ||
if (options.startDate.getTimezone != null) { | ||
formatS = VEvent.icalDTFormat; | ||
tzS = options.startDate.getTimezone(); | ||
} else { | ||
formatS = VEvent.icalDTUTCFormat; | ||
formatStart = VEvent.icalDTUTCFormat; | ||
} | ||
if (this.model.endDate.getTimezone != null) { | ||
formatEnd = VEvent.icalDTFormat; | ||
timezoneEnd = this.model.startDate.getTimezone(); | ||
} else { | ||
formatEnd = VEvent.icalDTUTCFormat; | ||
} | ||
} | ||
} | ||
if (timezoneStart != null) { | ||
fieldStart += ";TZID=" + timezoneStart; | ||
} | ||
if (timezoneEnd != null) { | ||
fieldEnd += ";TZID=" + timezoneEnd; | ||
} | ||
if (this.model.rrule != null) { | ||
delete this.model.rrule.dtstart; | ||
rrule = new RRule(this.model.rrule).toString(); | ||
} | ||
stampDate = moment(this.model.stampDate); | ||
this.addRawField('UID', this.model.uid); | ||
this.addRawField('DTSTAMP', stampDate.format(VEvent.icalDTUTCFormat)); | ||
this.addRawField(fieldStart, moment(this.model.startDate).format(formatStart)); | ||
if (this.model.endDate != null) { | ||
this.addRawField(fieldEnd, moment(this.model.endDate).format(formatEnd)); | ||
} | ||
if (this.model.attendees != null) { | ||
_ref1 = this.model.attendees; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
attendee = _ref1[_i]; | ||
status = ((_ref2 = attendee.details) != null ? _ref2.status : void 0) || 'NEEDS-ACTION'; | ||
details = ";PARTSTAT=" + status; | ||
name = ((_ref3 = attendee.details) != null ? _ref3.name : void 0) || attendee.email; | ||
details += ";CN=" + name; | ||
this.addRawField("ATTENDEE" + details, "mailto:" + attendee.email); | ||
} | ||
} | ||
this.addRawField('CATEGORIES', this.model.categories || null); | ||
this.addRawField('DESCRIPTION', this.model.description || null); | ||
this.addRawField('DURATION', this.model.duration || null); | ||
this.addRawField('LOCATION', this.model.location || null); | ||
this.addRawField('ORGANIZER', this.model.organizer || null); | ||
this.addRawField('RRULE', rrule || null); | ||
return this.addRawField('SUMMARY', this.model.summary || null); | ||
}; | ||
VEvent.prototype.extract = function() { | ||
var UTCFormat, allDay, attendees, daysNum, dtend, dtstart, duration, endDate, hoursNum, iCalFormat, minutesNum, rrule, rruleOptions, secondsNum, stampDate, startDate, timezone, timezoneEnd, timezoneStart, uid, weeksNum, _, _ref1, _ref10, _ref11, _ref12, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9; | ||
uid = this.getRawField('UID'); | ||
stampDate = ((_ref1 = this.getRawField('DTSTAMP')) != null ? _ref1.value : void 0) || moment(); | ||
dtstart = this.getRawField('DTSTART'); | ||
if (dtstart != null) { | ||
startDate = dtstart.value; | ||
if (((_ref2 = dtstart.details) != null ? _ref2.length : void 0) > 0) { | ||
if (dtstart.details[0] === 'VALUE=DATE') { | ||
timezoneStart = 'UTC'; | ||
allDay = true; | ||
} else { | ||
_ref3 = dtstart.details[0].split('='), _ = _ref3[0], timezoneStart = _ref3[1]; | ||
if (__indexOf.call(VALID_TZ_LIST, timezoneStart) < 0) { | ||
timezoneStart = 'UTC'; | ||
} | ||
if (options.endDate.getTimezone != null) { | ||
formatE = VEvent.icalDTFormat; | ||
tzE = options.startDate.getTimezone(); | ||
} else { | ||
formatE = VEvent.icalDTUTCFormat; | ||
} | ||
} | ||
} else { | ||
timezoneStart = 'UTC'; | ||
} | ||
if (tzS) { | ||
fieldS += ";TZID=" + tzS; | ||
} else { | ||
startDate = moment.tz(moment(), 'UTC').format(iCalFormat); | ||
timezoneStart = 'UTC'; | ||
} | ||
dtend = this.getRawField('DTEND'); | ||
endDate = (dtend != null ? dtend.value : void 0) || null; | ||
duration = ((_ref4 = this.getRawField('DURATION')) != null ? _ref4.value : void 0) || null; | ||
UTCFormat = 'YYYYMMDDTHHmmss[Z]'; | ||
iCalFormat = 'YYYYMMDDTHHmmss'; | ||
if ((endDate != null) && (duration != null)) { | ||
duration = null; | ||
} else if (!(endDate != null) && !(duration != null)) { | ||
endDate = moment.tz(startDate, iCalFormat, timezoneStart.add(1, 'd'.toDate())); | ||
} else if (!(endDate != null) && (duration != null)) { | ||
weeksNum = helpers.iCalDurationToUnitValue(duration, 'W'); | ||
daysNum = helpers.iCalDurationToUnitValue(duration, 'D'); | ||
hoursNum = helpers.iCalDurationToUnitValue(duration, 'H'); | ||
minutesNum = helpers.iCalDurationToUnitValue(duration, 'M'); | ||
secondsNum = helpers.iCalDurationToUnitValue(duration, 'S'); | ||
endDate = moment.tz(startDate, iCalFormat, timezoneStart); | ||
endDate = endDate.add(weeksNum, 'w'.add(daysNum, 'd'.add(hoursNum, 'h'.add(minutesNum, 'm'.add(secondsNum, 's'.toDate()))))); | ||
duration = null; | ||
} else if (endDate != null) { | ||
if (((_ref5 = dtend.details) != null ? _ref5.length : void 0) > 0) { | ||
_ref6 = dtstart.details[0].split('='), _ = _ref6[0], timezoneEnd = _ref6[1]; | ||
if (__indexOf.call(VALID_TZ_LIST, timezoneEnd) < 0) { | ||
timezoneEnd = 'UTC'; | ||
} | ||
} else { | ||
timezoneEnd = 'UTC'; | ||
} | ||
if (tzE) { | ||
fieldE += ";TZID=" + tzE; | ||
endDate = moment.tz(endDate, iCalFormat, timezoneEnd).toDate(); | ||
} | ||
rrule = (_ref7 = this.getRawField('RRULE')) != null ? _ref7.value : void 0; | ||
if (rrule != null) { | ||
if (timezoneStart !== 'UTC') { | ||
timezone = timezoneStart; | ||
} | ||
this.fields[fieldS] = moment(options.startDate).format(formatS); | ||
this.fields[fieldE] = moment(options.endDate).format(formatE); | ||
rruleOptions = RRule.parseString(rrule); | ||
} | ||
} | ||
attendees = this.getRawField('ATTENDEE', true); | ||
attendees = attendees != null ? attendees.map(function(attendee) { | ||
var detail, details, email, key, name, status, _i, _len, _ref10, _ref11, _ref8, _ref9; | ||
email = attendee.value.replace('mailto:', ''); | ||
if (((_ref8 = attendee.details) != null ? _ref8.length : void 0) > 0) { | ||
details = {}; | ||
_ref9 = attendee.details; | ||
for (_i = 0, _len = _ref9.length; _i < _len; _i++) { | ||
detail = _ref9[_i]; | ||
if (detail.indexOf('PARTSTAT') !== -1) { | ||
_ref10 = detail.split('='), key = _ref10[0], status = _ref10[1]; | ||
details.status = status; | ||
} else if (detail.indexOf('CN') !== -1) { | ||
_ref11 = detail.split('='), key = _ref11[0], name = _ref11[1]; | ||
details.name = name; | ||
} | ||
} | ||
} else { | ||
details = { | ||
status: 'NEEDS-ACTION', | ||
name: email | ||
}; | ||
} | ||
return { | ||
email: email, | ||
details: details | ||
}; | ||
}) : void 0; | ||
return this.model = { | ||
uid: (uid != null ? uid.value : void 0) || uuid.v1(), | ||
stampDate: moment.tz(stampDate, UTCFormat, 'UTC').toDate(), | ||
startDate: moment.tz(startDate, iCalFormat, timezoneStart.toDate()), | ||
endDate: endDate, | ||
duration: duration, | ||
attendees: attendees, | ||
categories: ((_ref8 = this.getRawField('CATEGORIES')) != null ? _ref8.value : void 0) || null, | ||
description: ((_ref9 = this.getRawField('DESCRIPTION')) != null ? _ref9.value : void 0) || null, | ||
location: ((_ref10 = this.getRawField('LOCATION')) != null ? _ref10.value : void 0) || null, | ||
organizer: ((_ref11 = this.getRawField('ORGANIZER')) != null ? _ref11.value : void 0) || null, | ||
rrule: rruleOptions || null, | ||
summary: ((_ref12 = this.getRawField('SUMMARY')) != null ? _ref12.value : void 0) || null, | ||
allDay: allDay || null, | ||
timezone: timezone || null | ||
}; | ||
}; | ||
@@ -310,3 +719,3 @@ return VEvent; | ||
function VTimezone(options) { | ||
var diff, vdaylight, vstandard; | ||
var diff, tzurl, vdaylight, vstandard; | ||
VTimezone.__super__.constructor.apply(this, arguments); | ||
@@ -316,6 +725,12 @@ if (!options) { | ||
} | ||
this.fields = { | ||
TZID: options.timezone, | ||
TZURL: "http://tzurl.org/zoneinfo/" + options.timezone + ".ics" | ||
}; | ||
tzurl = "http://tzurl.org/zoneinfo/" + options.timezone + ".ics"; | ||
this.rawFields = [ | ||
{ | ||
key: 'TZID', | ||
value: options.timezone | ||
}, { | ||
key: 'TZURL', | ||
value: tzurl | ||
} | ||
]; | ||
diff = moment.tz(options.startDate, options.timezone).format('ZZ'); | ||
@@ -367,2 +782,3 @@ vstandard = new VStandard(options.startDate, diff, diff); | ||
function VStandard(options) { | ||
var dtstart; | ||
VStandard.__super__.constructor.apply(this, arguments); | ||
@@ -372,7 +788,15 @@ if (!options) { | ||
} | ||
this.fields = { | ||
DTSTART: moment(options.startDate).format(VStandard.icalDTFormat), | ||
TZOFFSETFROM: options.startShift, | ||
TZOFFSETTO: options.endShift | ||
}; | ||
dtstart = moment(options.startDate.format(VStandard.icalDTFormat)); | ||
this.rawFields = [ | ||
{ | ||
key: 'DTSTART', | ||
value: dtstart | ||
}, { | ||
key: 'TZOFFSETFROM', | ||
value: options.startShift | ||
}, { | ||
key: 'TZOFFSETTO', | ||
value: options.endShift | ||
} | ||
]; | ||
} | ||
@@ -391,2 +815,3 @@ | ||
function VDaylight(options) { | ||
var dtstart; | ||
VDaylight.__super__.constructor.apply(this, arguments); | ||
@@ -396,7 +821,15 @@ if (!options) { | ||
} | ||
this.fields = { | ||
DTSTART: moment(options.startDate).format(VDaylight.icalDTFormat), | ||
TZOFFSETFROM: options.startShift, | ||
TZOFFSETTO: options.endShift | ||
}; | ||
dtstart = moment(options.startDate.format(VDaylight.icalDTFormat)); | ||
this.rawFields = [ | ||
{ | ||
key: 'DTSTART', | ||
value: dtstart | ||
}, { | ||
key: 'TZOFFSETFROM', | ||
value: options.startShift | ||
}, { | ||
key: 'TZOFFSETTO', | ||
value: options.endShift | ||
} | ||
]; | ||
} | ||
@@ -442,7 +875,7 @@ | ||
FakeStream.prototype.setEncoding = function() { | ||
throw 'not implemented'; | ||
throw new Error('not implemented'); | ||
}; | ||
FakeStream.prototype.pipe = function() { | ||
throw 'not implemented'; | ||
throw new Error('not implemented'); | ||
}; | ||
@@ -510,3 +943,3 @@ | ||
lineParser = function(line) { | ||
var detail, details, key, pname, pvalue, tuple, value, _i, _len, _ref, _ref1, _results; | ||
var detail, details, key, pname, pvalue, tuple, value, _i, _len, _ref1, _ref2, _results; | ||
tuple = line.trim().split(':'); | ||
@@ -516,8 +949,8 @@ if (tuple.length < 2) { | ||
} else { | ||
key = tuple[0]; | ||
tuple.shift(); | ||
value = tuple.join(''); | ||
key = tuple.shift(); | ||
value = tuple.join(':'); | ||
if (key === "BEGIN") { | ||
return createComponent(value); | ||
} else if (key === "END") { | ||
component.extract(); | ||
return component = component.parent; | ||
@@ -527,9 +960,8 @@ } else if (!((component != null) || (result != null))) { | ||
} else if ((key != null) && key !== '' && (component != null)) { | ||
_ref = key.split(';'), key = _ref[0], details = 2 <= _ref.length ? __slice.call(_ref, 1) : []; | ||
component.fields[key] = value; | ||
_ref1 = key.split(';'), key = _ref1[0], details = 2 <= _ref1.length ? __slice.call(_ref1, 1) : []; | ||
component.addRawField(key, value, details); | ||
_results = []; | ||
for (_i = 0, _len = details.length; _i < _len; _i++) { | ||
detail = details[_i]; | ||
_ref1 = detail.split('='), pname = _ref1[0], pvalue = _ref1[1]; | ||
_results.push(component.fields["" + key + "-" + pname] = pvalue); | ||
_results.push((_ref2 = detail.split('='), pname = _ref2[0], pvalue = _ref2[1], _ref2)); | ||
} | ||
@@ -536,0 +968,0 @@ return _results; |
{ | ||
"name": "cozy-ical", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Cozy-Ical provides ICal Parser, generators and helpers", | ||
"main": "lib/index", | ||
"main": "src/index", | ||
"scripts": { | ||
"test": "mocha test/index.coffee --reporter spec --compilers coffee:coffee-script --colors", | ||
"test": "cake tests", | ||
"build": "coffee -cb --output lib/ src/", | ||
@@ -37,12 +37,16 @@ "prepublish": "npm run build" | ||
"dependencies": { | ||
"moment-timezone": "0.2.2", | ||
"moment-timezone": "0.2.4", | ||
"rrule": "2.1.0", | ||
"lazy": "1.0.11" | ||
"lazy": "1.0.11", | ||
"printit": "0.1.3", | ||
"extend": "2.0.0", | ||
"uuid": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "= 1.4.0", | ||
"mocha": "~1.12.0", | ||
"should": "~1.2.0", | ||
"chai": "~1.7.2" | ||
"coffee-script": "1.8.0", | ||
"mocha": "2.0.1", | ||
"should": "4.1.0", | ||
"time": "0.11.0", | ||
"coffeelint": "1.6.1" | ||
} | ||
} |
@@ -28,3 +28,3 @@ cozy-ical | ||
var cal = new VCalendar({ | ||
organization: 'Cozy Cloud', | ||
organization: 'Cozy Cloud', | ||
title: 'Cozy Calendar' | ||
@@ -35,4 +35,4 @@ }); | ||
var vtodo = new VTodo({ | ||
startDate: date, | ||
summary: 'jhon', | ||
startDate: date, | ||
summary: 'jhon', | ||
description: 'my description' | ||
@@ -117,2 +117,64 @@ }); | ||
## Notes on iCal support | ||
This library is meant to support all iCal features as defined in [RFC 5545](https://tools.ietf.org/html/rfc5545). Thus it's not fully supporting everything yet, here is the list of unsupported fields: | ||
### vEvent | ||
* ATTACH | ||
* CLASS | ||
* COMMENT | ||
* CONTACT | ||
* CREATED | ||
* EXDATE | ||
* GEO | ||
* LAST-MOD | ||
* PRIORITY | ||
* RECURRENCE-ID | ||
* RELATED-TO | ||
* RESOURCES | ||
* RDATE | ||
* RS-STATUS | ||
* SEQ | ||
* STATUS | ||
* TRANSPARENCY | ||
* URL | ||
### vTodo | ||
* ATTACH | ||
* ATTENDEE | ||
* CATEGORIES | ||
* CLASS | ||
* COMMENT | ||
* CONTACT | ||
* COMPLETED | ||
* CREATED | ||
* DESCRIPTION | ||
* EXDATE | ||
* GEO | ||
* LAST-MOD | ||
* LOCATION | ||
* ORGANIZER | ||
* PRECENT | ||
* PRIORITY | ||
* RDATE | ||
* RECURID | ||
* RELATED | ||
* RESOURCES | ||
* RRULE | ||
* RSTATUS | ||
* SEQ | ||
* STATUS | ||
* URL | ||
### vAlarm | ||
* TRIGGER related to END | ||
### vJournal | ||
* not supported at all | ||
### vFreeBusy | ||
* not supported at all | ||
### vTimezone | ||
* not supported at all | ||
## What is Cozy? | ||
@@ -129,3 +191,3 @@ | ||
## Community | ||
## Community | ||
@@ -132,0 +194,0 @@ You can reach the Cozy community via various support: |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78636
19
1748
196
6
5
+ Addedextend@2.0.0
+ Addedprintit@0.1.3
+ Addeduuid@^2.0.1
+ Addedextend@2.0.0(transitive)
+ Addedmoment-timezone@0.2.4(transitive)
+ Addedprintit@0.1.3(transitive)
+ Addeduuid@2.0.3(transitive)
- Removedmoment-timezone@0.2.2(transitive)
Updatedmoment-timezone@0.2.4