README.md 2.47 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();

20
21
cal.setDomain('sebbo.net');

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
46
47
48
49
50
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
76
77
78
79
```



## 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.


### 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

#### 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
80
81
82
#### options.location (String)
Appointment location

83
84
85
86
87
88
89
90
91
#### 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
92
	location: 'Room 123',
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
	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()
Return Calendar as a String.