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

Sebastian Pekarek's avatar
Sebastian Pekarek committed
3
4
[![Build Status](https://travis-ci.org/sebbo2002/ical-generator.png?branch=master)](https://travis-ci.org/sebbo2002/ical-generator)

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

7

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

	npm install ical-generator

12

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

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

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

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



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

Use this method to set your feed's name.


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
### 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

Sebastian Pekarek's avatar
Sebastian Pekarek committed
76
77
78
#### options.allDay (Bool)
Appointment is for the whole day

79
80
81
82
83
84
85
86
87
#### 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
88
89
90
#### options.location (String)
Appointment location

91
92
93
94
95
96
97
98
99
#### 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
100
	location: 'Room 123',
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
	organizer: {
		name: 'Organizer\'s Name',
		email: 'organizer@example.com'
	}
});
```

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


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

Sebastian Pekarek's avatar
Sebastian Pekarek committed
127
128
129
### length()
Returns the ammount of events in the calendar.

130
131
### clear()
Empty the Calender.
Sebastian Pekarek's avatar
Sebastian Pekarek committed
132
133
134
135
136
137
138
139
140
141
142


## Tests

´´´javascript
// simple unit tests
mocha -R spec

// coverage test
istanbul cover _mocha -- -R spec
´´´