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

Sebastian Pekarek's avatar
Sebastian Pekarek committed
3
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
Sebastian Pekarek's avatar
Sebastian Pekarek committed
4
[![CI Status](https://img.shields.io/travis/sebbo2002/ical-generator.svg?style=flat-square)](https://travis-ci.org/sebbo2002/ical-generator)
5
<!-- [![Test Coverage](https://sebbo.helium.uberspace.de/teamcity-badges/ICalGenerator_UnitTests/coverage-istanbul)](https://ci.sebbo.net/project.html?projectId=ICalGenerator&tab=preport_project1_Test_Coverage&guest=1) -->
Sebastian Pekarek's avatar
Sebastian Pekarek committed
6

7
8
This is the SRCT fork of Sebbo2002's ical-generator

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

12

Sebastian Pekarek's avatar
Sebastian Pekarek committed
13
14
15
16
## Installation

	npm install ical-generator

17

Sebastian Pekarek's avatar
Sebastian Pekarek committed
18
19
20
21
22
23
24
25
26
27
## Upgrade from 0.1.x

ical-generator 0.2.0 introduces a completely new API, but because you guys used 0.1.x a lot, the old API still works. So
you should be able to upgrade from ical-generator 0.1.x to 0.2.0 without any code changes. In case you need the old API
docs, you can find the deprecated documentation [here](https://github.com/sebbo2002/ical-generator/blob/0.1.10/README.md).

In case you have any issues with the new API, feel free to [create an issue](https://github.com/sebbo2002/ical-generator/issues/new).


## Quick Start
Sebastian Pekarek's avatar
Sebastian Pekarek committed
28
29
30
31

```javascript
var ical = require('ical-generator'),
	http = require('http'),
Sebastian Pekarek's avatar
Sebastian Pekarek committed
32
	cal = ical({domain: 'github.com', name: 'my first iCal'});
Sebastian Pekarek's avatar
Sebastian Pekarek committed
33

Sebastian Pekarek's avatar
Sebastian Pekarek committed
34
35
// overwrite domain
cal.domain('sebbo.net');
36

Sebastian Pekarek's avatar
Sebastian Pekarek committed
37
cal.createEvent({
Sebastian Pekarek's avatar
Sebastian Pekarek committed
38
39
40
41
	start: new Date(),
	end: new Date(new Date().getTime() + 3600000),
	summary: 'Example Event',
	description: 'It works ;)',
Sebastian Pekarek's avatar
Sebastian Pekarek committed
42
	location: 'my room',
Sebastian Pekarek's avatar
Sebastian Pekarek committed
43
44
45
46
47
	url: 'http://sebbo.net/'
});

http.createServer(function(req, res) {
	cal.serve(res);
Sebastian Pekarek's avatar
Sebastian Pekarek committed
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
}).listen(3000, '127.0.0.1', function() {
    console.log('Server running at http://127.0.0.1:3000/');
});
```


## Just another example

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

    // Create new Calendar and set optional fields
    cal = ical({
        domain: 'sebbo.net',
        prodId: {company: 'superman-industries.com', product: 'ical-generator'},
        name: 'My Testfeed',
        timezone: 'Europe/Berlin'
    });

// You can also set values like this…
cal.domain('sebbo.net');

// … or get values
cal.domain(); // --> "sebbo.net"

// create a new event
var event = cal.createEvent({
    start: new Date(),
    end: new Date(new Date().getTime() + 3600000),
    timestamp: new Date(),
    summary: 'My Event',
    organizer: 'Sebastian Pekarek <mail@example.com>'
});

// like above, you can also set/change values like this…
event.summary('My Super Mega Awesome Event');

// get the iCal string
cal.toString(); // --> "BEGIN:VCALENDAR…"


// You can also create events directly with ical()
cal = ical({
    domain: 'sebbo.net',
    prodId: '//superman-industries.com//ical-generator//EN',
    events: [
        {
            start: new Date(),
            end: new Date(new Date().getTime() + 3600000),
            timestamp: new Date(),
            summary: 'My Event',
            organizer: 'Sebastian Pekarek <mail@example.com>'
        }
    ]
}).toString();
103
104
105
106
107
108
```



## API

Sebastian Pekarek's avatar
Sebastian Pekarek committed
109
### ical-generator
110

Sebastian Pekarek's avatar
Sebastian Pekarek committed
111
#### ical([_Object_ options])
112

Sebastian Pekarek's avatar
Sebastian Pekarek committed
113
Creates a new [Calendar](#calendar) ([`ICalCalendar`](#calendar)).
114

Sebastian Pekarek's avatar
Sebastian Pekarek committed
115
116
117
118
119
120
121
122
123
124
```javascript
var ical = require('ical-generator'),
    cal = ical();
```

You can pass options to setup your calendar or use setters to do this.

```javascript
var ical = require('ical-generator'),
    cal = ical({domain: 'sebbo.net'});
Sebastian Pekarek's avatar
Sebastian Pekarek committed
125

Sebastian Pekarek's avatar
Sebastian Pekarek committed
126
// is the same as
Sebastian Pekarek's avatar
Sebastian Pekarek committed
127

Sebastian Pekarek's avatar
Sebastian Pekarek committed
128
cal = ical().domain('sebbo.net');
Sebastian Pekarek's avatar
Sebastian Pekarek committed
129

Sebastian Pekarek's avatar
Sebastian Pekarek committed
130
// is the same as
lee's avatar
lee committed
131

Sebastian Pekarek's avatar
Sebastian Pekarek committed
132
133
134
135
136
137
138
cal = ical();
cal.domain('sebbo.net');
```


### Calendar

Sebastian Pekarek's avatar
Sebastian Pekarek committed
139
#### domain([_String_ domain])
lee's avatar
lee committed
140

Sebastian Pekarek's avatar
Sebastian Pekarek committed
141
142
Use this method to set your server's hostname. It will be used to generate the feed's UID. Default hostname is your
server's one (`require('os').hostname()`).
lee's avatar
lee committed
143

144

Sebastian Pekarek's avatar
Sebastian Pekarek committed
145
#### prodId([_String_|_Object_ prodId])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
146
147
148

Use this method to overwrite the default Product Identifier (`//sebbo.net//ical-generator//EN`). `prodId` can be ether
a valid Product Identifier or an object:
149
150

```javascript
Sebastian Pekarek's avatar
Sebastian Pekarek committed
151
cal.prodId({
152
153
	company: 'My Company',
	product: 'My Product',
Sebastian Pekarek's avatar
Sebastian Pekarek committed
154
	language: 'EN' // optional, defaults to EN
155
});
Sebastian Pekarek's avatar
Sebastian Pekarek committed
156
157
158
159

// OR

cal.prodId('//My Company//My Product//EN');
160
161
162
```


Sebastian Pekarek's avatar
Sebastian Pekarek committed
163
#### name([_String_ name])
164

Sebastian's avatar
Sebastian committed
165
Use this method to set your feed's name. Is used to fill `NAME` and `X-WR-CALNAME` in your iCal file.
166
167


Sebastian's avatar
Sebastian committed
168
169
170
171
172
173
174
175
176
#### url([_String_ url])

Use this method to set your feed's URL.

```javascript
var cal = ical().url('https://example.com/calendar.ical');
```


Sebastian Pekarek's avatar
Sebastian Pekarek committed
177
#### timezone([_String_ timezone])
178

Sebastian's avatar
Sebastian committed
179
Use this method to set your feed's timezone. Is used to fill `TIMEZONE-ID` and `X-WR-TIMEZONE` in your iCal.
180
181

```javascript
Sebastian Pekarek's avatar
Sebastian Pekarek committed
182
183
184
var cal = ical().timezone('Europe/Berlin');
```

185
186
187
188
#### method([_String_ method])

Calendar method. May be any of the following: `publish`, `request`, `reply`, `add`, `cancel`, `refresh`, `counter`, `declinecounter`.

Sebastian Pekarek's avatar
Sebastian Pekarek committed
189

Sebastian's avatar
Sebastian committed
190
191
192
193
194
195
196
197
198
#### ttl([_Number_ ttl])

Use this method to set your feed's time to live. Is used to fill `REFRESH-INTERVAL` and `X-PUBLISHED-TTL` in your iCal.

```javascript
var cal = ical().ttl(60 * 60 * 24);
```


Sebastian Pekarek's avatar
Sebastian Pekarek committed
199
#### createEvent([_Object_ options])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
200
201
202
203
204
205
206
207
208
209
210

Creates a new [Event](#event) ([`ICalEvent`](#event)) and returns it. Use options to prefill the event's attributes.
Calling this method without options will create an empty event.

```javascript
var ical = require('ical-generator'),
    cal = ical(),
    event = cal.createEvent({summary: 'My Event'});

// overwrite event summary
event.summary('Your Event');
211
212
```

Sebastian Pekarek's avatar
Sebastian Pekarek committed
213

Sebastian Pekarek's avatar
Sebastian Pekarek committed
214
#### events([_Object_ events])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233

Add Events to calendar or return all attached events.

```javascript
var cal = ical();
cal.events([
    {
        start: new Date(),
        end: new Date(new Date().getTime() + 3600000),
        summary: 'Example Event',
        description: 'It works ;)',
        url: 'http://sebbo.net/'
    }
]);

cal.events(); // --> [ICalEvent]
```


Sebastian Pekarek's avatar
Sebastian Pekarek committed
234
#### save(**_String_ file**[, _Function_ cb])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
235
236
237
238

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


Sebastian Pekarek's avatar
Sebastian Pekarek committed
239
#### saveSync(**_String_ file**)
Sebastian Pekarek's avatar
Sebastian Pekarek committed
240
241
242
243

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


Sebastian Pekarek's avatar
Sebastian Pekarek committed
244
#### serve(**_http.ServerResponse_ response**)
Sebastian Pekarek's avatar
Sebastian Pekarek committed
245
246
247
248
249
250
251
252
253

Send Calendar to the User when using HTTP. See Quick Start above.


#### toString()

Return Calendar as a String.


Sebastian Pekarek's avatar
Sebastian Pekarek committed
254
255
256
257
258
259
#### toJSON()

Return a shallow copy of the calendar's options for JSON stringification. Can be used for persistance.
```javascript
var cal = ical(),
    json = JSON.stringify(cal);
Sebastian's avatar
Sebastian committed
260
261
262
    
// later
cal = ical(json);
Sebastian Pekarek's avatar
Sebastian Pekarek committed
263
264
```

Sebastian Pekarek's avatar
Sebastian Pekarek committed
265
266
267
268
269
270
271
272
273
274
275
276
277
#### length()

Returns the ammount of events in the calendar.


#### clear()

Empty the Calender.



### Event

Sebastian Pekarek's avatar
Sebastian Pekarek committed
278
#### uid([_String_|_Number_ uid]) or id([_String_|_Number_ id])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
279

Andi Sidwell's avatar
Andi Sidwell committed
280
Use this method to set the event's ID. If not set, an UID will be generated randomly.  When output, the ID will be suffixed with '@' + your calendar's domain.
Sebastian Pekarek's avatar
Sebastian Pekarek committed
281
282


283
#### sequence([_Number_ sequence])
284
285
286
287
288

Use this method to set the event's revision sequence number of the
calendar component within a sequence of revisions.


Sebastian Pekarek's avatar
Sebastian Pekarek committed
289
#### start([_Date_ start])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
290
291
292
293

Appointment date of beginning as Date object. This is required for all events!


Sebastian Pekarek's avatar
Sebastian Pekarek committed
294
#### end([_Date_ end])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
295

Sebastian's avatar
Sebastian committed
296
Appointment date of end as Date object.
Sebastian Pekarek's avatar
Sebastian Pekarek committed
297
298


Andi Sidwell's avatar
Andi Sidwell committed
299
300
301
302
303
304
305
#### timezone([_String_ timezone])

Use this method to set your event's timezone using the TZID property parameter on start and end dates, as per [date-time form #3 in section 3.3.5 of RFC 554](https://tools.ietf.org/html/rfc5545#section-3.3.5).

This and the 'floating' flag (see below) are mutually exclusive, and setting a timezone will unset the 'floating' flag.  If neither 'timezone' nor 'floating' are set, the date will be output with in UTC format (see [date-time form #2 in section 3.3.5 of RFC 554](https://tools.ietf.org/html/rfc5545#section-3.3.5)).


Sebastian Pekarek's avatar
Sebastian Pekarek committed
306
#### timestamp([_Date_ stamp]) or stamp([_Date_ stamp])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
307
308
309
310

Appointment date of creation as Date object. Default to `new Date()`.


Sebastian Pekarek's avatar
Sebastian Pekarek committed
311
#### allDay([_Boolean_ allDay])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
312
313
314
315

When allDay == true -> appointment is for the whole day


Sebastian Pekarek's avatar
Sebastian Pekarek committed
316
#### floating([_Boolean_ floating])
Andi Sidwell's avatar
Andi Sidwell committed
317

318
319
320
321
322
323
324
325
326
327
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.

Andi Sidwell's avatar
Andi Sidwell committed
328
329
This and the 'timezone' setting (see above) are mutually exclusive, and setting the floating flag will unset the 'timezone'.  If neither 'timezone' nor 'floating' are set, the date will be output with in UTC format (see [date-time form #2 in section 3.3.5 of RFC 554](https://tools.ietf.org/html/rfc5545#section-3.3.5)).

330

Sebastian Pekarek's avatar
Sebastian Pekarek committed
331
#### repeating([_Object_ repeating])
Andi Sidwell's avatar
Andi Sidwell committed
332

Sebastian Pekarek's avatar
Sebastian Pekarek committed
333
334
335
Appointment is a repeating event

```javascript
Sebastian Pekarek's avatar
Sebastian Pekarek committed
336
event.repeating({
Sebastian Pekarek's avatar
Sebastian Pekarek committed
337
338
339
    freq: 'MONTHLY', // required
    count: 5,
    interval: 2,
340
341
342
    until: new Date('Jan 01 2014 00:00:00 UTC'),
    byDay: ['su', 'mo'], // repeat only sunday and monday
    byMonth: [1, 2], // repeat only in january und february,
Sebastian's avatar
Sebastian committed
343
344
    byMonthDay: [1, 15], // repeat only on the 1st and 15th
    exclude: [new Date('Dec 25 2013 00:00:00 UTC')] // exclude these dates
Sebastian Pekarek's avatar
Sebastian Pekarek committed
345
346
347
348
});
```


Sebastian Pekarek's avatar
Sebastian Pekarek committed
349
#### summary([_String_ summary])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
350

Sebastian Pekarek's avatar
Sebastian Pekarek committed
351
Appointment summary, defaults to empty string.
Sebastian Pekarek's avatar
Sebastian Pekarek committed
352
353


Sebastian Pekarek's avatar
Sebastian Pekarek committed
354
#### description([_String_ description])
355
356
357

Appointment description

Sebastian Pekarek's avatar
Sebastian Pekarek committed
358

Sebastian's avatar
Sebastian committed
359
360
361
362
363
#### htmlDescription([_String_ htmlDescription])

Some calendar apps may support HTML descriptions. Like in emails, supported HTML tags and styling is limited. 


Sebastian Pekarek's avatar
Sebastian Pekarek committed
364
#### location([_String_ location])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
365

Sebastian Pekarek's avatar
Sebastian Pekarek committed
366
367
Appointment location

Sebastian Pekarek's avatar
Sebastian Pekarek committed
368

Sebastian Pekarek's avatar
Sebastian Pekarek committed
369
#### organizer([_String_|Object organizer])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
370

371
372
373
Appointment organizer

```javascript
Sebastian Pekarek's avatar
Sebastian Pekarek committed
374
375
376
cal.organizer({
    name: 'Organizer\'s Name',
    email: 'organizer@example.com'
377
378
});

Sebastian Pekarek's avatar
Sebastian Pekarek committed
379
// OR
Lisa Övermyr's avatar
Lisa Övermyr committed
380

Sebastian Pekarek's avatar
Sebastian Pekarek committed
381
382
cal.organizer('Organizer\'s Name <organizer@example.com>');
```
Lisa Övermyr's avatar
Lisa Övermyr committed
383

384

Sebastian Pekarek's avatar
Sebastian Pekarek committed
385
#### createAttendee([_Object_ options])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

Creates a new [Attendee](#attendee) ([`ICalAttendee`](#attendee)) and returns it. Use options to prefill the attendee's attributes.
Calling this method without options will create an empty attendee.

```javascript
var ical = require('ical-generator'),
    cal = ical(),
    event = cal.createEvent(),
    attendee = event.createAttendee({email: 'hui@example.com', 'name': 'Hui'});

// overwrite attendee's email address
attendee.email('hui@example.net');

// add another attendee
event.createAttendee('Buh <buh@example.net>');
```


Sebastian Pekarek's avatar
Sebastian Pekarek committed
404
#### attendees([_Object_ attendees])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
405
406
407
408
409
410
411
412
413
414
415
416
417
418

Add Attendees to the event or return all attached attendees.

```javascript
var event = ical().createEvent();
cal.attendees([
    {email: 'a@example.com', name: 'Person A'},
    {email: 'b@example.com', name: 'Person B'}
]);

cal.attendees(); // --> [ICalAttendee, ICalAttendee]
```


Sebastian Pekarek's avatar
Sebastian Pekarek committed
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#### createAlarm([_Object_ options])

Creates a new [Alarm](#alarm) ([`ICalAlarm`](#alarm)) and returns it. Use options to prefill the alarm's attributes.
Calling this method without options will create an empty alarm.

```javascript
var ical = require('ical-generator'),
    cal = ical(),
    event = cal.createEvent(),
    alarm = event.createAlarm({type: 'display', trigger: 300});

// add another alarm
event.createAlarm({
    type: 'audio',
    trigger: 300, // 5min before event
});
```


#### alarms([_Object_ alarms])

Add alarms to the event or return all attached alarms.

```javascript
var event = ical().createEvent();
cal.alarms([
    {type: 'display', trigger: 600},
    {type: 'audio', trigger: 300}
]);

Akiva Gordon's avatar
Akiva Gordon committed
449
cal.alarms(); // --> [ICalAlarm, ICalAlarm]
Sebastian Pekarek's avatar
Sebastian Pekarek committed
450
451
452
```


Sebastian Pekarek's avatar
Sebastian Pekarek committed
453
#### url([_String_ url])
454

Sebastian Pekarek's avatar
Sebastian Pekarek committed
455
Appointment URL
456
457


Sebastian Pekarek's avatar
Sebastian Pekarek committed
458
#### status([_String_ status])
459

Akiva Gordon's avatar
Akiva Gordon committed
460
Appointment status. May be any of the following: `confirmed`, `tentative`, `cancelled`.
Sebastian Pekarek's avatar
Sebastian Pekarek committed
461

Sebastian Pekarek's avatar
Sebastian Pekarek committed
462
463


Sebastian Pekarek's avatar
Sebastian Pekarek committed
464
465
### Attendee

Sebastian Pekarek's avatar
Sebastian Pekarek committed
466
#### name([_String_ name])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
467
468
469
470

Use this method to set the attendee's name.


Sebastian Pekarek's avatar
Sebastian Pekarek committed
471
#### email([_String_ email])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
472
473
474
475

The attendee's email address. An email address is required for every attendee!


Sebastian Pekarek's avatar
Sebastian Pekarek committed
476
#### role([_String_ role])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
477

Sebastian Pekarek's avatar
Sebastian Pekarek committed
478
Set the attendee's role, defaults to `REQ-PARTICIPANT`. May be one of the following: `req-participant`, `non-participant`
Sebastian Pekarek's avatar
Sebastian Pekarek committed
479
480


Sebastian Pekarek's avatar
Sebastian Pekarek committed
481
#### status([_String_ status])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
482

Sebastian Pekarek's avatar
Sebastian Pekarek committed
483
Set the attendee's status. May be one of the following: `accepted`, `tentative`, `declined`
Sebastian Pekarek's avatar
Sebastian Pekarek committed
484
485


486
487
#### type([_String_ type])

Sebastian Pekarek's avatar
Sebastian Pekarek committed
488
Set the attendee's type. May be one of the following: `individual`, `group`, `resource`, `room`, `unknown` (See [Section 4.2.3](https://tools.ietf.org/html/rfc2445#section-4.2.3))
489
490
491



Sebastian Pekarek's avatar
Sebastian Pekarek committed
492
#### delegatesTo(**_ICalAttendee_|_Object_ attendee**)
Sebastian Pekarek's avatar
Sebastian Pekarek committed
493
494
495
496
497
498
499
500
501
502
503
504

Creates a new Attendee if passed object is not already an attendee. Will set the delegatedTo and delegatedFrom attributes.

```javascript
var cal = ical(),
    event = cal.createEvent(),
    attendee = cal.createAttendee();

attendee.delegatesTo({email: 'foo@bar.com', name: 'Foo'});
```


Sebastian Pekarek's avatar
Sebastian Pekarek committed
505
#### delegatesFrom(**_ICalAttendee_|_Object_ attendee**)
Sebastian Pekarek's avatar
Sebastian Pekarek committed
506
507
508
509
510
511
512
513
514
515
516
517
518

Creates a new Attendee if passed object is not already an attendee. Will set the delegatedTo and delegatedFrom attributes.

```javascript
var cal = ical(),
    event = cal.createEvent(),
    attendee = cal.createAttendee();

attendee.delegatesFrom({email: 'foo@bar.com', name: 'Foo'});
```



Sebastian Pekarek's avatar
Sebastian Pekarek committed
519
520
521
522
523
524
525
### Alarm

#### type([_String_ type])

Use this method to set the alarm type. Right now, `audio` and `display` is supported.


Sebastian Pekarek's avatar
Sebastian Pekarek committed
526
#### trigger([_Number_|_Date_ trigger]) / triggerBefore([_Number_|_Date_ trigger])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
527
528
529
530
531
532
533
534
535
536
537
538
539

Use this method to set the alarm time.

```javascript
var cal = ical(),
    event = cal.createEvent(),
    alarm = cal.createAlarm();

alarm.trigger(600); // -> 10 minutes before event starts
alarm.trigger(new Date()); // -> now
```


Sebastian Pekarek's avatar
Sebastian Pekarek committed
540
#### triggerAfter([_Number_|_Date_ trigger])
Sebastian Pekarek's avatar
Sebastian Pekarek committed
541
542
543
544
545
546
547
548

Use this method to set the alarm time.

```javascript
var cal = ical(),
    event = cal.createEvent(),
    alarm = cal.createAlarm();

Tobias Mersmann's avatar
Tobias Mersmann committed
549
550
alarm.triggerAfter(600); // -> 10 minutes after the event finishes
alarm.triggerAfter(new Date()); // -> now
Sebastian Pekarek's avatar
Sebastian Pekarek committed
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
```


#### repeat([_Number_ repeat])

Use this method to repeat the alarm.

```javascript
var cal = ical(),
    event = cal.createEvent(),

// repeat the alarm 4 times every 5 minutes…
cal.createAlarm({
    repeat: 4,
    interval: 300
});
```


#### interval([_Number_ interval])

Use this method to set the alarm's interval.

```javascript
var cal = ical(),
    event = cal.createEvent(),

// repeat the alarm 4 times every 5 minutes…
cal.createAlarm({
    repeat: 4,
    interval: 300
});
```


#### attach([_String_|_Object_ attach])

Alarm attachment; used to set the alarm sound if type = audio. Defaults to "Basso".

```javascript
var cal = ical(),
    event = cal.createEvent(),

event.createAlarm({
    attach: 'https://example.com/notification.aud'
});

// OR

event.createAlarm({
    attach: {
        uri: 'https://example.com/notification.aud',
        mime: 'audio/basic'
    }
});
```


#### description([_String_| description])

Alarm description; used to set the alarm message if type = display. Defaults to the event's summary.




Sebastian Pekarek's avatar
Sebastian Pekarek committed
616
617
## Tests

Sebastian Pekarek's avatar
Sebastian Pekarek committed
618
```
Sebastian Pekarek's avatar
Sebastian Pekarek committed
619
npm test
620
621
622
623
624
```


## Copyright and license

Sebastian Pekarek's avatar
Sebastian Pekarek committed
625
Copyright (c) Sebastian Pekarek under the [MIT license](LICENSE).