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

Sebastian Pekarek's avatar
Sebastian Pekarek committed
3
4
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
[![CI Status](https://sebbo.helium.uberspace.de/ci-badges/2)](https://ci.sebbo.net/projects/2)
Sebastian Pekarek's avatar
Sebastian Pekarek committed
5

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

8

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

	npm install ical-generator

13

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

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

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

Sebastian Pekarek's avatar
Sebastian Pekarek committed
23
24
25
26
27
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
28
	location: 'my room',
Sebastian Pekarek's avatar
Sebastian Pekarek committed
29
30
31
32
33
34
35
	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/');
36
37
38
39
40
41
42
43
44
45
46
```



## 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
47
48
49
50
51
### setName(name)

Use this method to set your feed's name.


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

Use this method to set your feed's timezone.


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
### 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

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#### 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
97
98
99
#### options.allDay (Bool)
Appointment is for the whole day

100
101
102
103
104
105
106
107
108
109
110
#### options.floating (Bool)
Appointment is a "floating" time. From [section 3.3.12 of RFC 554](https://tools.ietf.org/html/rfc5545#section-3.3.12):

> Time values of this type are said to be "floating" and are not
> bound to any time zone in particular.  They are used to represent
> the same hour, minute, and second value regardless of which time
> zone is currently being observed.  For example, an event can be
> defined that indicates that an individual will be busy from 11:00
> AM to 1:00 PM every day, no matter which time zone the person is
> in.  In these cases, a local time can be specified.

111
112
113
114
115
116
117
118
119
#### 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
120
121
122
#### options.location (String)
Appointment location

123
124
125
126
127
128
129
130
131
#### 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
132
	location: 'Room 123',
133
134
135
136
137
138
139
140
141
142
	organizer: {
		name: 'Organizer\'s Name',
		email: 'organizer@example.com'
	}
});
```

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

Lisa Övermyr's avatar
Lisa Övermyr committed
143
144
145
146
147
148
#### 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.

149
150
151
152
153
154
155
156
157
158
159
160
161
162

### 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()
163
164
Return Calendar as a String.

Sebastian Pekarek's avatar
Sebastian Pekarek committed
165
166
167
### length()
Returns the ammount of events in the calendar.

168
169
### clear()
Empty the Calender.
Sebastian Pekarek's avatar
Sebastian Pekarek committed
170
171
172
173


## Tests

Sebastian Pekarek's avatar
Sebastian Pekarek committed
174
```javascript
Sebastian Pekarek's avatar
Sebastian Pekarek committed
175
176
177
178
// simple unit tests
mocha -R spec

// coverage test
Sebastian Pekarek's avatar
Sebastian Pekarek committed
179
npm test
180
181
182
183
184
185
```


## Copyright and license

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