Skip to content

Commit e00ef66

Browse files
committed
initial API
0 parents  commit e00ef66

16 files changed

+851
-0
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
node_modules/

Diff for: Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
test:
2+
NODE_ENV=test ./node_modules/.bin/mocha --check-leaks \
3+
-w \
4+
--reporter landing \
5+
test/*
6+
7+
.PHONY: test

Diff for: README.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
VObject
2+
=====
3+
4+
VObject allows you to easily manipulate iCalendar objects using JavaScript. Implements [rfc5545](http://tools.ietf.org/html/rfc5545).
5+
6+
Installation
7+
---
8+
9+
Example
10+
---
11+
12+
### Create a Calendar
13+
14+
> The top-level element in iCalendar is the Calendaring and Scheduling Core Object, a collection of calendar and scheduling information. Typically, this information will consist of a single iCalendar object.
15+
16+
17+
```js
18+
var calendar = VObject.calendar();
19+
```
20+
21+
> The body of the iCalendar object (the icalbody) is made up of a list of calendar properties and one or more calendar components.
22+
23+
### Create a Event
24+
25+
```js
26+
var event = VObject.event();
27+
event.setSummary('Hello World!');
28+
```
29+
30+
Then, add the event to that calendar (events need to be added to a calendar to be a proper iCal object):
31+
32+
```js
33+
calendar.addComponent(event);
34+
```
35+
36+
Then, to ICS:
37+
38+
```js
39+
calendar.stringify();
40+
```
41+
42+
API
43+
---
44+
45+
### VObject.calendar
46+
47+
#### getMethod
48+
#### setMethod
49+
#### stringify
50+
51+
### VObject.event
52+
53+
#### setUID (required)
54+
#### getUID
55+
#### setSummary
56+
#### getSummary
57+
#### setDescription
58+
#### setDescription
59+
#### setLocation
60+
#### setLocation
61+
#### setStatus
62+
#### getStatus
63+
#### setDTStamp
64+
#### getDTStamp
65+
#### setSequence
66+
#### getSequence (Default 0)
67+
#### setCreated
68+
#### getCreated
69+
70+
### VObject.attendee
71+
72+
73+
74+
### VObject.component
75+
#### addProperty
76+
#### setProperty
77+
#### getProperty
78+
#### getPropertyValue

Diff for: index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib/vobject');

Diff for: lib/attendee.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
var Property = require('./property');
2+
3+
// http://tools.ietf.org/html/rfc5545#section-3.8.4.1
4+
// This property defines an "Attendee" within a calendar component.
5+
6+
module.exports = function() {
7+
var attendee = Property('ATTENDEE');
8+
9+
// CUType
10+
// http://tools.ietf.org/html/rfc5545#section-3.2.3
11+
attendee.setCUType = function(value) {
12+
attendee.setParameter('CUTYPE', value);
13+
};
14+
15+
attendee.getCUType = function() {
16+
return attendee.getParameter('CUTYPE');
17+
};
18+
19+
// Role
20+
// http://tools.ietf.org/html/rfc5545#section-3.2.16
21+
attendee.setRole = function(value) {
22+
attendee.setParameter('ROLE', value);
23+
};
24+
25+
attendee.getRole = function() {
26+
return attendee.getParameter('ROLE');
27+
};
28+
29+
// PartStat
30+
// http://tools.ietf.org/html/rfc5545#section-3.2.12
31+
attendee.setPartStat = function(value) {
32+
attendee.setParameter('PARTSTAT', value);
33+
};
34+
35+
attendee.getPartStat = function() {
36+
return attendee.getParameter('PARTSTAT');
37+
};
38+
39+
// RSVP Expectation
40+
// http://tools.ietf.org/html/rfc5545#section-3.2.17
41+
attendee.setRSVP = function(value) {
42+
attendee.setParameter('RSVP', value);
43+
};
44+
45+
attendee.getRSVP = function() {
46+
return attendee.getParameter('RSVP');
47+
};
48+
49+
// CN
50+
// http://tools.ietf.org/html/rfc5545#section-3.2.2
51+
attendee.setCN = function(value) {
52+
attendee.setParameter('CN', value);
53+
};
54+
55+
attendee.getCN = function() {
56+
return attendee.getParameter('CN');
57+
};
58+
59+
return attendee;
60+
};

Diff for: lib/calendar.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var Component = require('./component');
2+
3+
module.exports = function() {
4+
var calendar = Component('VCALENDAR');
5+
6+
// Calendar Properties
7+
// http://tools.ietf.org/html/rfc5545#section-3.7
8+
9+
// Version
10+
// http://tools.ietf.org/html/rfc5545#section-3.7.4
11+
calendar.addProperty('VERSION', '2');
12+
13+
// Calendar Scale
14+
// http://tools.ietf.org/html/rfc5545#section-3.7.1
15+
calendar.addProperty('CALSCALE', 'GREGORIAN');
16+
17+
// Product Identifier
18+
// http://tools.ietf.org/html/rfc5545#section-3.7.3
19+
calendar.addProperty('PRODID', '-//Sunrise Atelier, Inc//EN');
20+
21+
// Method
22+
// http://tools.ietf.org/html/rfc5545#section-3.7.2
23+
calendar.setMethod = function(method) {
24+
calendar.addProperty('METHOD', method);
25+
};
26+
27+
calendar.getMethod = function() {
28+
return calendar.getPropertyValue('METHOD');
29+
};
30+
31+
return calendar;
32+
};

Diff for: lib/component.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
var Property = require('./property');
2+
3+
module.exports = function(name) {
4+
var component = {};
5+
6+
component.name = (name || 'VCALENDAR').toUpperCase();
7+
8+
// http://tools.ietf.org/html/rfc5545#section-3.6
9+
component.components = {};
10+
11+
// http://tools.ietf.org/html/rfc5545#section-3.7
12+
component.properties = {};
13+
14+
// addProperty
15+
// name, value
16+
component.addProperty = function(name, value) {
17+
var property = Property(name, value);
18+
component.properties[name] = component.properties[name] || [];
19+
component.properties[name].push(property);
20+
};
21+
22+
// setProperty
23+
// unique
24+
component.setProperty = function(name, value) {
25+
var property = Property(name, value);
26+
component.properties[name] = [property];
27+
};
28+
29+
// getProperty
30+
// returns first Property when index is undefined
31+
component.getProperty = function(name, index) {
32+
return (this.properties[name] || [])[index || 0];
33+
};
34+
35+
// getPropertyValue
36+
component.getPropertyValue = function(name, index) {
37+
var property = component.getProperty(name, index);
38+
if (!property) {
39+
return undefined;
40+
}
41+
return property.value;
42+
};
43+
44+
// addComponent
45+
component.addComponent = function(childComponent) {
46+
component.components[childComponent.name] = component.properties[childComponent.name] || [];
47+
component.components[childComponent.name].push(childComponent);
48+
};
49+
50+
// stringifyToArray
51+
component.stringifyToArray = function() {
52+
var lines = [];
53+
54+
// BEGIN:VCALENDAR
55+
lines.push(['BEGIN', component.name].join(':'));
56+
57+
// Stringify .properties
58+
for(var name in component.properties) {
59+
component.properties[name].forEach(function(property) {
60+
lines.push(property.stringify());
61+
});
62+
}
63+
64+
// Stringify .components
65+
for(var name in component.components) {
66+
component.components[name].forEach(function(component) {
67+
lines = lines.concat(component.stringifyToArray());
68+
});
69+
}
70+
71+
// END:VCALENDAR
72+
lines.push(['END', component.name].join(':'));
73+
74+
return lines;
75+
};
76+
77+
return component;
78+
};

Diff for: lib/event.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
var Component = require('./component');
2+
3+
module.exports = function() {
4+
// http://tools.ietf.org/html/rfc5545#section-3.6.1
5+
// Provide a grouping of component properties that describe an event.
6+
var event = Component('VEVENT');
7+
8+
// Sequence to 0 (Default)
9+
event.setProperty('SEQUENCE', '0');
10+
11+
// http://tools.ietf.org/html/rfc5545#section-3.8.4.7
12+
event.setUID = function(UID) {
13+
event.setProperty('UID', UID);
14+
};
15+
16+
event.getUID = function() {
17+
return event.getPropertyValue('UID');
18+
};
19+
20+
// http://tools.ietf.org/html/rfc5545#section-3.8.1.12
21+
event.setSummary = function(summary) {
22+
event.setProperty('SUMMARY', summary);
23+
};
24+
25+
event.getSummary = function() {
26+
return event.getPropertyValue('SUMMARY');
27+
};
28+
29+
// http://tools.ietf.org/html/rfc5545#section-3.8.1.5
30+
event.setDescription = function(description) {
31+
event.setProperty('DESCRIPTION', description);
32+
};
33+
34+
event.getDescription = function() {
35+
return event.getPropertyValue('DESCRIPTION');
36+
};
37+
38+
// http://tools.ietf.org/html/rfc5545#section-3.8.1.7
39+
event.setLocation = function(location) {
40+
event.setProperty('LOCATION', location);
41+
};
42+
43+
event.getLocation = function() {
44+
return event.getPropertyValue('LOCATION');
45+
};
46+
47+
// http://tools.ietf.org/html/rfc5545#section-3.8.1.11
48+
event.setStatus = function(status) {
49+
event.setProperty('STATUS', status);
50+
};
51+
52+
event.getStatus = function() {
53+
return event.getPropertyValue('STATUS');
54+
};
55+
56+
// http://tools.ietf.org/html/rfc5545#section-3.8.7.2
57+
event.setDTStamp = function(dtstamp) {
58+
event.setProperty('DTSTAMP', dtstamp);
59+
};
60+
61+
event.getDTStamp = function() {
62+
return event.getPropertyValue('DTSTAMP');
63+
};
64+
65+
// http://tools.ietf.org/html/rfc5545#section-3.8.7.4
66+
event.setSequence = function(sequence) {
67+
event.setProperty('SEQUENCE', sequence);
68+
};
69+
70+
event.getSequence = function() {
71+
return event.getPropertyValue('SEQUENCE');
72+
};
73+
74+
// http://tools.ietf.org/html/rfc5545#section-3.8.7.1
75+
event.setCreated = function(sequence) {
76+
event.setProperty('CREATED', sequence);
77+
};
78+
79+
event.getCreated = function() {
80+
return event.getPropertyValue('CREATED');
81+
};
82+
83+
return event;
84+
};

0 commit comments

Comments
 (0)