README.md 3.78 KB
Newer Older
Sebastian Pekarek's avatar
Sebastian Pekarek committed
1
2
# ical-generator

Sebastian Pekarek's avatar
Sebastian Pekarek committed
3
[![License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
Sebastian Pekarek's avatar
Sebastian Pekarek committed
4
5
[![CI Status](https://sebbo.helium.uberspace.de/teamcity-badges/iCalGenerator_Develop/status)](https://ci.sebbo.net/viewType.html?buildTypeId=iCalGenerator_Develop&guest=1)
[![Code Coverage](https://sebbo.helium.uberspace.de/teamcity-badges/iCalGenerator_Develop/coverage-istanbul)](https://ci.sebbo.net/viewType.html?buildTypeId=iCalGenerator_Develop&guest=1)
Sebastian Pekarek's avatar
Sebastian Pekarek committed
6

Sebastian Pekarek's avatar
Sebastian Pekarek committed
7
8
ical-generator is a small piece of code which generates ical calendar files. I use this to generate subscriptionable calendar feeds.

9

Sebastian Pekarek's avatar
Sebastian Pekarek committed
10
11
12
13
## Installation

	npm install ical-generator

14

Sebastian Pekarek's avatar
Sebastian Pekarek committed
15
16
17
18
19
20
21
## Example

```javascript
var ical = require('ical-generator'),
	http = require('http'),
	cal = ical();

Sebastian Pekarek's avatar
Sebastian Pekarek committed
22
cal.setDomain('sebbo.net').setName('my first iCal');
23

Sebastian Pekarek's avatar
Sebastian Pekarek committed
24
25
26
27
28
cal.addEvent({
	start: new Date(),
	end: new Date(new Date().getTime() + 3600000),
	summary: 'Example Event',
	description: 'It works ;)',
Sebastian Pekarek's avatar
Sebastian Pekarek committed
29
	location: 'my room',
Sebastian Pekarek's avatar
Sebastian Pekarek committed
30
31
32
33
34
35
36
	url: 'http://sebbo.net/'
});

http.createServer(function(req, res) {
	cal.serve(res);
}).listen(3000, '127.0.0.1');
console.log('Server running at http://127.0.0.1:3000/');
37
38
39
40
41
42
43
44
45
46
47
```



## API

### setDomain(domain)

Use this method to set your server's hostname. It will be used to generate the feed's UID. Default hostname is localhost.


Sebastian Pekarek's avatar
Sebastian Pekarek committed
48
49
50
51
52
### setName(name)

Use this method to set your feed's name.


lee's avatar
lee committed
53
54
55
56
57
### setTZ(timezone)

Use this method to set your feed's timezone.


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
### setProdID(prodID)

This method is used to overwrite the default ProdID:

```javascript
cal.setProdID({
	company: 'My Company',
	product: 'My Product',
	language: 'EN'
});
```


### addEvent(options)
Add an event. Options is an plain object, that configure the event.

#### options.uid (String)
Event UID. If not set, an UID will be generated randomly.

#### options.start (Date Object, required)
Appointment date of beginning

#### options.end (Date Object, required)
Appointment date of end

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#### options.repeating (Plain Object)
Appointment is a repeating event

```javascript
cal.addEvent({
	/* Other options */
	repeating: {
		freq: 'MONTHLY', // required
		count: 5,
		interval: 2,
		until: new Date("Jan 01 2014 00:00:00 UTC")
	}
});
```

Sebastian Pekarek's avatar
Sebastian Pekarek committed
98
99
100
#### options.allDay (Bool)
Appointment is for the whole day

101
102
103
104
105
106
107
108
109
#### options.stamp (Date Object)
Appointment date of creation

#### options.summary (String, required)
Appointment summary

#### options.description (String)
Appointment description

Sebastian Pekarek's avatar
Sebastian Pekarek committed
110
111
112
#### options.location (String)
Appointment location

113
114
115
116
117
118
119
120
121
#### options.organizer (Plain Object)
Appointment organizer

```javascript
cal.addEvent({
	start: new Date(),
	end: new Date(new Date().getTime() + 3600000),
	summary: 'Example Event',
	description: 'Appointment with Organizer',
Sebastian Pekarek's avatar
Sebastian Pekarek committed
122
	location: 'Room 123',
123
124
125
126
127
128
129
130
131
132
	organizer: {
		name: 'Organizer\'s Name',
		email: 'organizer@example.com'
	}
});
```

#### options.url (String)
Appointment Website

Lisa Övermyr's avatar
Lisa Övermyr committed
133
134
135
136
137
138
#### options.method (String)
Appointment method. May be any of the following: publish, request, reply, add, cancel, refresh, counter, declinecounter.

#### options.status (String)
Appointment status. May be any of the following: confirmed, tenative, cancelled.

139
140
141
142
143
144
145
146
147
148
149
150
151
152

### save(file[, cb])
Save Calendar to disk asynchronously using [fs.writeFile](http://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback)


### saveSync(file)
Save Calendar to disk synchronously using [fs.writeFileSync](http://nodejs.org/api/fs.html#fs_fs_writefilesync_filename_data_options)


### serve(response)
Send Calendar to the User when using HTTP. See example above.


### toString()
153
154
Return Calendar as a String.

Sebastian Pekarek's avatar
Sebastian Pekarek committed
155
156
157
### length()
Returns the ammount of events in the calendar.

158
159
### clear()
Empty the Calender.
Sebastian Pekarek's avatar
Sebastian Pekarek committed
160
161
162
163


## Tests

Sebastian Pekarek's avatar
Sebastian Pekarek committed
164
```javascript
Sebastian Pekarek's avatar
Sebastian Pekarek committed
165
166
167
168
169
// simple unit tests
mocha -R spec

// coverage test
istanbul cover _mocha -- -R spec
170
171
172
173
174
175
```


## Copyright and license

Copyright (c) Sebastian Pekarek under the [MIT license](LICENSE).