ical-generator 3.6.2-develop.4 → 4.0.0-develop.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/event.js DELETED
@@ -1,820 +0,0 @@
1
- 'use strict';
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ICalEventClass = exports.ICalEventTransparency = exports.ICalEventBusyStatus = exports.ICalEventStatus = void 0;
7
- const uuid_random_1 = __importDefault(require("uuid-random"));
8
- const tools_1 = require("./tools");
9
- const attendee_1 = __importDefault(require("./attendee"));
10
- const alarm_1 = __importDefault(require("./alarm"));
11
- const category_1 = __importDefault(require("./category"));
12
- const types_1 = require("./types");
13
- var ICalEventStatus;
14
- (function (ICalEventStatus) {
15
- ICalEventStatus["CONFIRMED"] = "CONFIRMED";
16
- ICalEventStatus["TENTATIVE"] = "TENTATIVE";
17
- ICalEventStatus["CANCELLED"] = "CANCELLED";
18
- })(ICalEventStatus = exports.ICalEventStatus || (exports.ICalEventStatus = {}));
19
- var ICalEventBusyStatus;
20
- (function (ICalEventBusyStatus) {
21
- ICalEventBusyStatus["FREE"] = "FREE";
22
- ICalEventBusyStatus["TENTATIVE"] = "TENTATIVE";
23
- ICalEventBusyStatus["BUSY"] = "BUSY";
24
- ICalEventBusyStatus["OOF"] = "OOF";
25
- })(ICalEventBusyStatus = exports.ICalEventBusyStatus || (exports.ICalEventBusyStatus = {}));
26
- var ICalEventTransparency;
27
- (function (ICalEventTransparency) {
28
- ICalEventTransparency["TRANSPARENT"] = "TRANSPARENT";
29
- ICalEventTransparency["OPAQUE"] = "OPAQUE";
30
- })(ICalEventTransparency = exports.ICalEventTransparency || (exports.ICalEventTransparency = {}));
31
- var ICalEventClass;
32
- (function (ICalEventClass) {
33
- ICalEventClass["PUBLIC"] = "PUBLIC";
34
- ICalEventClass["PRIVATE"] = "PRIVATE";
35
- ICalEventClass["CONFIDENTIAL"] = "CONFIDENTIAL";
36
- })(ICalEventClass = exports.ICalEventClass || (exports.ICalEventClass = {}));
37
- /**
38
- * Usually you get an `ICalCalendar` object like this:
39
- * ```javascript
40
- * import ical from 'ical-generator';
41
- * const calendar = ical();
42
- * const event = calendar.createEvent();
43
- * ```
44
- */
45
- class ICalEvent {
46
- /**
47
- * Constructor of [[`ICalEvent`]. The calendar reference is
48
- * required to query the calendar's timezone when required.
49
- *
50
- * @param data Calendar Event Data
51
- * @param calendar Reference to ICalCalendar object
52
- */
53
- constructor(data, calendar) {
54
- this.data = {
55
- id: (0, uuid_random_1.default)(),
56
- sequence: 0,
57
- start: null,
58
- end: null,
59
- recurrenceId: null,
60
- timezone: null,
61
- stamp: new Date(),
62
- allDay: false,
63
- floating: false,
64
- repeating: null,
65
- summary: '',
66
- location: null,
67
- description: null,
68
- organizer: null,
69
- attendees: [],
70
- alarms: [],
71
- categories: [],
72
- status: null,
73
- busystatus: null,
74
- priority: null,
75
- url: null,
76
- attachments: [],
77
- transparency: null,
78
- created: null,
79
- lastModified: null,
80
- class: null,
81
- x: []
82
- };
83
- this.calendar = calendar;
84
- if (!calendar) {
85
- throw new Error('`calendar` option required!');
86
- }
87
- data.id && this.id(data.id);
88
- data.sequence !== undefined && this.sequence(data.sequence);
89
- data.start && this.start(data.start);
90
- data.end !== undefined && this.end(data.end);
91
- data.recurrenceId !== undefined && this.recurrenceId(data.recurrenceId);
92
- data.timezone !== undefined && this.timezone(data.timezone);
93
- data.stamp !== undefined && this.stamp(data.stamp);
94
- data.allDay !== undefined && this.allDay(data.allDay);
95
- data.floating !== undefined && this.floating(data.floating);
96
- data.repeating !== undefined && this.repeating(data.repeating);
97
- data.summary !== undefined && this.summary(data.summary);
98
- data.location !== undefined && this.location(data.location);
99
- data.description !== undefined && this.description(data.description);
100
- data.organizer !== undefined && this.organizer(data.organizer);
101
- data.attendees !== undefined && this.attendees(data.attendees);
102
- data.alarms !== undefined && this.alarms(data.alarms);
103
- data.categories !== undefined && this.categories(data.categories);
104
- data.status !== undefined && this.status(data.status);
105
- data.busystatus !== undefined && this.busystatus(data.busystatus);
106
- data.priority !== undefined && this.priority(data.priority);
107
- data.url !== undefined && this.url(data.url);
108
- data.attachments !== undefined && this.attachments(data.attachments);
109
- data.transparency !== undefined && this.transparency(data.transparency);
110
- data.created !== undefined && this.created(data.created);
111
- data.lastModified !== undefined && this.lastModified(data.lastModified);
112
- data.class !== undefined && this.class(data.class);
113
- data.x !== undefined && this.x(data.x);
114
- }
115
- id(id) {
116
- if (id === undefined) {
117
- return this.data.id;
118
- }
119
- this.data.id = String(id);
120
- return this;
121
- }
122
- uid(id) {
123
- return id === undefined ? this.id() : this.id(id);
124
- }
125
- sequence(sequence) {
126
- if (sequence === undefined) {
127
- return this.data.sequence;
128
- }
129
- const s = parseInt(String(sequence), 10);
130
- if (isNaN(s)) {
131
- throw new Error('`sequence` must be a number!');
132
- }
133
- this.data.sequence = sequence;
134
- return this;
135
- }
136
- start(start) {
137
- if (start === undefined) {
138
- return this.data.start;
139
- }
140
- this.data.start = (0, tools_1.checkDate)(start, 'start');
141
- if (this.data.start && this.data.end && (0, tools_1.toDate)(this.data.start).getTime() > (0, tools_1.toDate)(this.data.end).getTime()) {
142
- const t = this.data.start;
143
- this.data.start = this.data.end;
144
- this.data.end = t;
145
- }
146
- return this;
147
- }
148
- end(end) {
149
- if (end === undefined) {
150
- return this.data.end;
151
- }
152
- if (end === null) {
153
- this.data.end = null;
154
- return this;
155
- }
156
- this.data.end = (0, tools_1.checkDate)(end, 'end');
157
- if (this.data.start && this.data.end && (0, tools_1.toDate)(this.data.start).getTime() > (0, tools_1.toDate)(this.data.end).getTime()) {
158
- const t = this.data.start;
159
- this.data.start = this.data.end;
160
- this.data.end = t;
161
- }
162
- return this;
163
- }
164
- recurrenceId(recurrenceId) {
165
- if (recurrenceId === undefined) {
166
- return this.data.recurrenceId;
167
- }
168
- if (recurrenceId === null) {
169
- this.data.recurrenceId = null;
170
- return this;
171
- }
172
- this.data.recurrenceId = (0, tools_1.checkDate)(recurrenceId, 'recurrenceId');
173
- return this;
174
- }
175
- timezone(timezone) {
176
- if (timezone === undefined && this.data.timezone !== null) {
177
- return this.data.timezone;
178
- }
179
- if (timezone === undefined) {
180
- return this.calendar.timezone();
181
- }
182
- this.data.timezone = timezone && timezone !== 'UTC' ? timezone.toString() : null;
183
- if (this.data.timezone) {
184
- this.data.floating = false;
185
- }
186
- return this;
187
- }
188
- stamp(stamp) {
189
- if (stamp === undefined) {
190
- return this.data.stamp;
191
- }
192
- this.data.stamp = (0, tools_1.checkDate)(stamp, 'stamp');
193
- return this;
194
- }
195
- timestamp(stamp) {
196
- if (stamp === undefined) {
197
- return this.stamp();
198
- }
199
- return this.stamp(stamp);
200
- }
201
- allDay(allDay) {
202
- if (allDay === undefined) {
203
- return this.data.allDay;
204
- }
205
- this.data.allDay = Boolean(allDay);
206
- return this;
207
- }
208
- /**
209
- * Set the event's floating flag. This unsets the event's timezone.
210
- * Events whose floating flag is set to true always take place at the
211
- * same time, regardless of the time zone.
212
- *
213
- * @since 0.2.0
214
- */
215
- floating(floating) {
216
- if (floating === undefined) {
217
- return this.data.floating;
218
- }
219
- this.data.floating = Boolean(floating);
220
- if (this.data.floating) {
221
- this.data.timezone = null;
222
- }
223
- return this;
224
- }
225
- repeating(repeating) {
226
- if (repeating === undefined) {
227
- return this.data.repeating;
228
- }
229
- if (!repeating) {
230
- this.data.repeating = null;
231
- return this;
232
- }
233
- if ((0, tools_1.isRRule)(repeating) || typeof repeating === 'string') {
234
- this.data.repeating = repeating;
235
- return this;
236
- }
237
- this.data.repeating = {
238
- freq: (0, tools_1.checkEnum)(types_1.ICalEventRepeatingFreq, repeating.freq)
239
- };
240
- if (repeating.count) {
241
- if (!isFinite(repeating.count)) {
242
- throw new Error('`repeating.count` must be a finite number!');
243
- }
244
- this.data.repeating.count = repeating.count;
245
- }
246
- if (repeating.interval) {
247
- if (!isFinite(repeating.interval)) {
248
- throw new Error('`repeating.interval` must be a finite number!');
249
- }
250
- this.data.repeating.interval = repeating.interval;
251
- }
252
- if (repeating.until !== undefined) {
253
- this.data.repeating.until = (0, tools_1.checkDate)(repeating.until, 'repeating.until');
254
- }
255
- if (repeating.byDay) {
256
- const byDayArray = Array.isArray(repeating.byDay) ? repeating.byDay : [repeating.byDay];
257
- this.data.repeating.byDay = byDayArray.map(day => (0, tools_1.checkEnum)(types_1.ICalWeekday, day));
258
- }
259
- if (repeating.byMonth) {
260
- const byMonthArray = Array.isArray(repeating.byMonth) ? repeating.byMonth : [repeating.byMonth];
261
- this.data.repeating.byMonth = byMonthArray.map(month => {
262
- if (typeof month !== 'number' || month < 1 || month > 12) {
263
- throw new Error('`repeating.byMonth` contains invalid value `' + month + '`!');
264
- }
265
- return month;
266
- });
267
- }
268
- if (repeating.byMonthDay) {
269
- const byMonthDayArray = Array.isArray(repeating.byMonthDay) ? repeating.byMonthDay : [repeating.byMonthDay];
270
- this.data.repeating.byMonthDay = byMonthDayArray.map(monthDay => {
271
- if (typeof monthDay !== 'number' || monthDay < -31 || monthDay > 31 || monthDay === 0) {
272
- throw new Error('`repeating.byMonthDay` contains invalid value `' + monthDay + '`!');
273
- }
274
- return monthDay;
275
- });
276
- }
277
- if (repeating.bySetPos) {
278
- if (!this.data.repeating.byDay) {
279
- throw '`repeating.bySetPos` must be used along with `repeating.byDay`!';
280
- }
281
- const bySetPosArray = Array.isArray(repeating.bySetPos) ? repeating.bySetPos : [repeating.bySetPos];
282
- this.data.repeating.bySetPos = bySetPosArray.map(bySetPos => {
283
- if (typeof bySetPos !== 'number' || bySetPos < -366 || bySetPos > 366 || bySetPos === 0) {
284
- throw '`repeating.bySetPos` contains invalid value `' + bySetPos + '`!';
285
- }
286
- return bySetPos;
287
- });
288
- }
289
- if (repeating.exclude) {
290
- const excludeArray = Array.isArray(repeating.exclude) ? repeating.exclude : [repeating.exclude];
291
- this.data.repeating.exclude = excludeArray.map((exclude, i) => {
292
- return (0, tools_1.checkDate)(exclude, `repeating.exclude[${i}]`);
293
- });
294
- }
295
- if (repeating.startOfWeek) {
296
- this.data.repeating.startOfWeek = (0, tools_1.checkEnum)(types_1.ICalWeekday, repeating.startOfWeek);
297
- }
298
- return this;
299
- }
300
- summary(summary) {
301
- if (summary === undefined) {
302
- return this.data.summary;
303
- }
304
- this.data.summary = summary ? String(summary) : '';
305
- return this;
306
- }
307
- location(location) {
308
- if (location === undefined) {
309
- return this.data.location;
310
- }
311
- if (typeof location === 'string') {
312
- this.data.location = {
313
- title: location
314
- };
315
- return this;
316
- }
317
- if ((location && !location.title) ||
318
- ((location === null || location === void 0 ? void 0 : location.geo) && (!isFinite(location.geo.lat) || !isFinite(location.geo.lon)))) {
319
- throw new Error('`location` isn\'t formatted correctly. See https://sebbo2002.github.io/ical-generator/' +
320
- 'develop/reference/classes/ICalEvent.html#location');
321
- }
322
- this.data.location = location || null;
323
- return this;
324
- }
325
- description(description) {
326
- if (description === undefined) {
327
- return this.data.description;
328
- }
329
- if (description === null) {
330
- this.data.description = null;
331
- return this;
332
- }
333
- if (typeof description === 'string') {
334
- this.data.description = { plain: description };
335
- }
336
- else {
337
- this.data.description = description;
338
- }
339
- return this;
340
- }
341
- organizer(organizer) {
342
- if (organizer === undefined) {
343
- return this.data.organizer;
344
- }
345
- if (organizer === null) {
346
- this.data.organizer = null;
347
- return this;
348
- }
349
- this.data.organizer = (0, tools_1.checkNameAndMail)('organizer', organizer);
350
- return this;
351
- }
352
- /**
353
- * Creates a new [[`ICalAttendee`]] and returns it. Use options to prefill
354
- * the attendee's attributes. Calling this method without options will create
355
- * an empty attendee.
356
- *
357
- * ```javascript
358
- * const cal = ical();
359
- * const event = cal.createEvent();
360
- * const attendee = event.createAttendee({email: 'hui@example.com', name: 'Hui'});
361
- *
362
- * // add another attendee
363
- * event.createAttendee('Buh <buh@example.net>');
364
- * ```
365
- *
366
- * As with the organizer, you can also add an explicit `mailto` address.
367
- *
368
- * ```javascript
369
- * event.createAttendee({email: 'hui@example.com', name: 'Hui', mailto: 'another@mailto.com'});
370
- *
371
- * // overwrite an attendee's mailto address
372
- * attendee.mailto('another@mailto.net');
373
- * ```
374
- *
375
- * @since 0.2.0
376
- */
377
- createAttendee(data = {}) {
378
- if (data instanceof attendee_1.default) {
379
- this.data.attendees.push(data);
380
- return data;
381
- }
382
- if (typeof data === 'string') {
383
- data = (0, tools_1.checkNameAndMail)('data', data);
384
- }
385
- const attendee = new attendee_1.default(data, this);
386
- this.data.attendees.push(attendee);
387
- return attendee;
388
- }
389
- attendees(attendees) {
390
- if (!attendees) {
391
- return this.data.attendees;
392
- }
393
- attendees.forEach(attendee => this.createAttendee(attendee));
394
- return this;
395
- }
396
- /**
397
- * Creates a new [[`ICalAlarm`]] and returns it. Use options to prefill
398
- * the alarm's attributes. Calling this method without options will create
399
- * an empty alarm.
400
- *
401
- * ```javascript
402
- * const cal = ical();
403
- * const event = cal.createEvent();
404
- * const alarm = event.createAlarm({type: ICalAlarmType.display, trigger: 300});
405
- *
406
- * // add another alarm
407
- * event.createAlarm({
408
- * type: ICalAlarmType.audio,
409
- * trigger: 300, // 5min before event
410
- * });
411
- * ```
412
- *
413
- * @since 0.2.1
414
- */
415
- createAlarm(data = {}) {
416
- const alarm = data instanceof alarm_1.default ? data : new alarm_1.default(data, this);
417
- this.data.alarms.push(alarm);
418
- return alarm;
419
- }
420
- alarms(alarms) {
421
- if (!alarms) {
422
- return this.data.alarms;
423
- }
424
- alarms.forEach((alarm) => this.createAlarm(alarm));
425
- return this;
426
- }
427
- /**
428
- * Creates a new [[`ICalCategory`]] and returns it. Use options to prefill the categories' attributes.
429
- * Calling this method without options will create an empty category.
430
- *
431
- * ```javascript
432
- * const cal = ical();
433
- * const event = cal.createEvent();
434
- * const category = event.createCategory({name: 'APPOINTMENT'});
435
- *
436
- * // add another alarm
437
- * event.createCategory({
438
- * name: 'MEETING'
439
- * });
440
- * ```
441
- *
442
- * @since 0.3.0
443
- */
444
- createCategory(data = {}) {
445
- const category = data instanceof category_1.default ? data : new category_1.default(data);
446
- this.data.categories.push(category);
447
- return category;
448
- }
449
- categories(categories) {
450
- if (!categories) {
451
- return this.data.categories;
452
- }
453
- categories.forEach(category => this.createCategory(category));
454
- return this;
455
- }
456
- status(status) {
457
- if (status === undefined) {
458
- return this.data.status;
459
- }
460
- if (status === null) {
461
- this.data.status = null;
462
- return this;
463
- }
464
- this.data.status = (0, tools_1.checkEnum)(ICalEventStatus, status);
465
- return this;
466
- }
467
- busystatus(busystatus) {
468
- if (busystatus === undefined) {
469
- return this.data.busystatus;
470
- }
471
- if (busystatus === null) {
472
- this.data.busystatus = null;
473
- return this;
474
- }
475
- this.data.busystatus = (0, tools_1.checkEnum)(ICalEventBusyStatus, busystatus);
476
- return this;
477
- }
478
- priority(priority) {
479
- if (priority === undefined) {
480
- return this.data.priority;
481
- }
482
- if (priority === null) {
483
- this.data.priority = null;
484
- return this;
485
- }
486
- if (priority < 0 || priority > 9) {
487
- throw new Error('`priority` is invalid, musst be 0 ≤ priority ≤ 9.');
488
- }
489
- this.data.priority = Math.round(priority);
490
- return this;
491
- }
492
- url(url) {
493
- if (url === undefined) {
494
- return this.data.url;
495
- }
496
- this.data.url = url ? String(url) : null;
497
- return this;
498
- }
499
- /**
500
- * Adds an attachment to the event by adding the file URL to the calendar.
501
- *
502
- * `ical-generator` only supports external attachments. File attachments that
503
- * are directly included in the file are not supported, because otherwise the
504
- * calendar file could easily become unfavourably large.
505
- *
506
- * ```javascript
507
- * const cal = ical();
508
- * const event = cal.createEvent();
509
- * event.createAttachment('https://files.sebbo.net/calendar/attachments/foo');
510
- * ```
511
- *
512
- * @since 3.2.0-develop.1
513
- */
514
- createAttachment(url) {
515
- this.data.attachments.push(url);
516
- return this;
517
- }
518
- attachments(attachments) {
519
- if (!attachments) {
520
- return this.data.attachments;
521
- }
522
- attachments.forEach((attachment) => this.createAttachment(attachment));
523
- return this;
524
- }
525
- transparency(transparency) {
526
- if (transparency === undefined) {
527
- return this.data.transparency;
528
- }
529
- if (!transparency) {
530
- this.data.transparency = null;
531
- return this;
532
- }
533
- this.data.transparency = (0, tools_1.checkEnum)(ICalEventTransparency, transparency);
534
- return this;
535
- }
536
- created(created) {
537
- if (created === undefined) {
538
- return this.data.created;
539
- }
540
- if (created === null) {
541
- this.data.created = null;
542
- return this;
543
- }
544
- this.data.created = (0, tools_1.checkDate)(created, 'created');
545
- return this;
546
- }
547
- lastModified(lastModified) {
548
- if (lastModified === undefined) {
549
- return this.data.lastModified;
550
- }
551
- if (lastModified === null) {
552
- this.data.lastModified = null;
553
- return this;
554
- }
555
- this.data.lastModified = (0, tools_1.checkDate)(lastModified, 'lastModified');
556
- return this;
557
- }
558
- class(class_) {
559
- if (class_ === undefined) {
560
- return this.data.class;
561
- }
562
- if (class_ === null) {
563
- this.data.class = null;
564
- return this;
565
- }
566
- this.data.class = (0, tools_1.checkEnum)(ICalEventClass, class_);
567
- return this;
568
- }
569
- x(keyOrArray, value) {
570
- if (keyOrArray === undefined) {
571
- return (0, tools_1.addOrGetCustomAttributes)(this.data);
572
- }
573
- if (typeof keyOrArray === 'string' && typeof value === 'string') {
574
- (0, tools_1.addOrGetCustomAttributes)(this.data, keyOrArray, value);
575
- }
576
- if (typeof keyOrArray === 'object') {
577
- (0, tools_1.addOrGetCustomAttributes)(this.data, keyOrArray);
578
- }
579
- return this;
580
- }
581
- /**
582
- * Return a shallow copy of the events's options for JSON stringification.
583
- * Third party objects like moment.js values or RRule objects are stringified
584
- * as well. Can be used for persistence.
585
- *
586
- * ```javascript
587
- * const event = ical().createEvent();
588
- * const json = JSON.stringify(event);
589
- *
590
- * // later: restore event data
591
- * const calendar = ical().createEvent(JSON.parse(json));
592
- * ```
593
- *
594
- * @since 0.2.4
595
- */
596
- toJSON() {
597
- var _a;
598
- let repeating = null;
599
- if ((0, tools_1.isRRule)(this.data.repeating) || typeof this.data.repeating === 'string') {
600
- repeating = this.data.repeating.toString();
601
- }
602
- else if (this.data.repeating) {
603
- repeating = Object.assign({}, this.data.repeating, {
604
- until: (0, tools_1.toJSON)(this.data.repeating.until),
605
- exclude: (_a = this.data.repeating.exclude) === null || _a === void 0 ? void 0 : _a.map(d => (0, tools_1.toJSON)(d)),
606
- });
607
- }
608
- return Object.assign({}, this.data, {
609
- start: (0, tools_1.toJSON)(this.data.start) || null,
610
- end: (0, tools_1.toJSON)(this.data.end) || null,
611
- recurrenceId: (0, tools_1.toJSON)(this.data.recurrenceId) || null,
612
- stamp: (0, tools_1.toJSON)(this.data.stamp) || null,
613
- created: (0, tools_1.toJSON)(this.data.created) || null,
614
- lastModified: (0, tools_1.toJSON)(this.data.lastModified) || null,
615
- repeating,
616
- x: this.x()
617
- });
618
- }
619
- /**
620
- * Return generated event as a string.
621
- *
622
- * ```javascript
623
- * const event = ical().createEvent();
624
- * console.log(event.toString()); // → BEGIN:VEVENT…
625
- * ```
626
- */
627
- toString() {
628
- var _a, _b, _c, _d, _e;
629
- let g = '';
630
- if (!this.data.start) {
631
- throw new Error('No value for `start` in ICalEvent #' + this.data.id + ' given!');
632
- }
633
- // DATE & TIME
634
- g += 'BEGIN:VEVENT\r\n';
635
- g += 'UID:' + this.data.id + '\r\n';
636
- // SEQUENCE
637
- g += 'SEQUENCE:' + this.data.sequence + '\r\n';
638
- g += 'DTSTAMP:' + (0, tools_1.formatDate)(this.calendar.timezone(), this.data.stamp) + '\r\n';
639
- if (this.data.allDay) {
640
- g += 'DTSTART;VALUE=DATE:' + (0, tools_1.formatDate)(this.calendar.timezone(), this.data.start, true) + '\r\n';
641
- if (this.data.end) {
642
- g += 'DTEND;VALUE=DATE:' + (0, tools_1.formatDate)(this.calendar.timezone(), this.data.end, true) + '\r\n';
643
- }
644
- g += 'X-MICROSOFT-CDO-ALLDAYEVENT:TRUE\r\n';
645
- g += 'X-MICROSOFT-MSNCALENDAR-ALLDAYEVENT:TRUE\r\n';
646
- }
647
- else {
648
- g += (0, tools_1.formatDateTZ)(this.timezone(), 'DTSTART', this.data.start, this.data) + '\r\n';
649
- if (this.data.end) {
650
- g += (0, tools_1.formatDateTZ)(this.timezone(), 'DTEND', this.data.end, this.data) + '\r\n';
651
- }
652
- }
653
- // REPEATING
654
- if ((0, tools_1.isRRule)(this.data.repeating) || typeof this.data.repeating === 'string') {
655
- let repeating = this.data.repeating
656
- .toString()
657
- .replace(/\r\n/g, '\n')
658
- .split('\n')
659
- .filter(l => l && !l.startsWith('DTSTART:'))
660
- .join('\r\n');
661
- if (!repeating.includes('\r\n') && !repeating.startsWith('RRULE:')) {
662
- repeating = 'RRULE:' + repeating;
663
- }
664
- g += repeating.trim() + '\r\n';
665
- }
666
- else if (this.data.repeating) {
667
- g += 'RRULE:FREQ=' + this.data.repeating.freq;
668
- if (this.data.repeating.count) {
669
- g += ';COUNT=' + this.data.repeating.count;
670
- }
671
- if (this.data.repeating.interval) {
672
- g += ';INTERVAL=' + this.data.repeating.interval;
673
- }
674
- if (this.data.repeating.until) {
675
- g += ';UNTIL=' + (0, tools_1.formatDate)(this.calendar.timezone(), this.data.repeating.until, false, this.floating());
676
- }
677
- if (this.data.repeating.byDay) {
678
- g += ';BYDAY=' + this.data.repeating.byDay.join(',');
679
- }
680
- if (this.data.repeating.byMonth) {
681
- g += ';BYMONTH=' + this.data.repeating.byMonth.join(',');
682
- }
683
- if (this.data.repeating.byMonthDay) {
684
- g += ';BYMONTHDAY=' + this.data.repeating.byMonthDay.join(',');
685
- }
686
- if (this.data.repeating.bySetPos) {
687
- g += ';BYSETPOS=' + this.data.repeating.bySetPos.join(',');
688
- }
689
- if (this.data.repeating.startOfWeek) {
690
- g += ';WKST=' + this.data.repeating.startOfWeek;
691
- }
692
- g += '\r\n';
693
- // REPEATING EXCLUSION
694
- if (this.data.repeating.exclude) {
695
- if (this.data.allDay) {
696
- g += 'EXDATE;VALUE=DATE:' + this.data.repeating.exclude.map(excludedDate => {
697
- return (0, tools_1.formatDate)(this.calendar.timezone(), excludedDate, true);
698
- }).join(',') + '\r\n';
699
- }
700
- else {
701
- g += 'EXDATE';
702
- if (this.timezone()) {
703
- g += ';TZID=' + this.timezone() + ':' + this.data.repeating.exclude.map(excludedDate => {
704
- // This isn't a 'floating' event because it has a timezone;
705
- // but we use it to omit the 'Z' UTC specifier in formatDate()
706
- return (0, tools_1.formatDate)(this.timezone(), excludedDate, false, true);
707
- }).join(',') + '\r\n';
708
- }
709
- else {
710
- g += ':' + this.data.repeating.exclude.map(excludedDate => {
711
- return (0, tools_1.formatDate)(this.timezone(), excludedDate, false, this.floating());
712
- }).join(',') + '\r\n';
713
- }
714
- }
715
- }
716
- }
717
- // RECURRENCE
718
- if (this.data.recurrenceId) {
719
- g += (0, tools_1.formatDateTZ)(this.timezone(), 'RECURRENCE-ID', this.data.recurrenceId, this.data) + '\r\n';
720
- }
721
- // SUMMARY
722
- g += 'SUMMARY:' + (0, tools_1.escape)(this.data.summary, false) + '\r\n';
723
- // TRANSPARENCY
724
- if (this.data.transparency) {
725
- g += 'TRANSP:' + (0, tools_1.escape)(this.data.transparency, false) + '\r\n';
726
- }
727
- // LOCATION
728
- if ((_a = this.data.location) === null || _a === void 0 ? void 0 : _a.title) {
729
- g += 'LOCATION:' + (0, tools_1.escape)(this.data.location.title +
730
- (this.data.location.address ? '\n' + this.data.location.address : ''), false) + '\r\n';
731
- if (this.data.location.radius && this.data.location.geo) {
732
- g += 'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;' +
733
- (this.data.location.address ? 'X-ADDRESS=' + (0, tools_1.escape)(this.data.location.address, false) + ';' : '') +
734
- 'X-APPLE-RADIUS=' + (0, tools_1.escape)(this.data.location.radius, false) + ';' +
735
- 'X-TITLE=' + (0, tools_1.escape)(this.data.location.title, false) +
736
- ':geo:' + (0, tools_1.escape)((_b = this.data.location.geo) === null || _b === void 0 ? void 0 : _b.lat, false) + ',' +
737
- (0, tools_1.escape)((_c = this.data.location.geo) === null || _c === void 0 ? void 0 : _c.lon, false) + '\r\n';
738
- }
739
- if (this.data.location.geo) {
740
- g += 'GEO:' + (0, tools_1.escape)((_d = this.data.location.geo) === null || _d === void 0 ? void 0 : _d.lat, false) + ';' +
741
- (0, tools_1.escape)((_e = this.data.location.geo) === null || _e === void 0 ? void 0 : _e.lon, false) + '\r\n';
742
- }
743
- }
744
- // DESCRIPTION
745
- if (this.data.description) {
746
- g += 'DESCRIPTION:' + (0, tools_1.escape)(this.data.description.plain, false) + '\r\n';
747
- // HTML DESCRIPTION
748
- if (this.data.description.html) {
749
- g += 'X-ALT-DESC;FMTTYPE=text/html:' + (0, tools_1.escape)(this.data.description.html, false) + '\r\n';
750
- }
751
- }
752
- // ORGANIZER
753
- if (this.data.organizer) {
754
- g += 'ORGANIZER;CN="' + (0, tools_1.escape)(this.data.organizer.name, true) + '"';
755
- if (this.data.organizer.sentBy) {
756
- g += ';SENT-BY="mailto:' + (0, tools_1.escape)(this.data.organizer.sentBy, true) + '"';
757
- }
758
- if (this.data.organizer.email && this.data.organizer.mailto) {
759
- g += ';EMAIL=' + (0, tools_1.escape)(this.data.organizer.email, false);
760
- }
761
- if (this.data.organizer.email) {
762
- g += ':mailto:' + (0, tools_1.escape)(this.data.organizer.mailto || this.data.organizer.email, false);
763
- }
764
- g += '\r\n';
765
- }
766
- // ATTENDEES
767
- this.data.attendees.forEach(function (attendee) {
768
- g += attendee.toString();
769
- });
770
- // ALARMS
771
- this.data.alarms.forEach(function (alarm) {
772
- g += alarm.toString();
773
- });
774
- // CATEGORIES
775
- if (this.data.categories.length > 0) {
776
- g += 'CATEGORIES:' + this.data.categories.map(function (category) {
777
- return category.toString();
778
- }).join() + '\r\n';
779
- }
780
- // URL
781
- if (this.data.url) {
782
- g += 'URL;VALUE=URI:' + (0, tools_1.escape)(this.data.url, false) + '\r\n';
783
- }
784
- // ATTACHMENT
785
- if (this.data.attachments.length > 0) {
786
- this.data.attachments.forEach(url => {
787
- g += 'ATTACH:' + (0, tools_1.escape)(url, false) + '\r\n';
788
- });
789
- }
790
- // STATUS
791
- if (this.data.status) {
792
- g += 'STATUS:' + this.data.status.toUpperCase() + '\r\n';
793
- }
794
- // BUSYSTATUS
795
- if (this.data.busystatus) {
796
- g += 'X-MICROSOFT-CDO-BUSYSTATUS:' + this.data.busystatus.toUpperCase() + '\r\n';
797
- }
798
- // PRIORITY
799
- if (this.data.priority !== null) {
800
- g += 'PRIORITY:' + this.data.priority + '\r\n';
801
- }
802
- // CUSTOM X ATTRIBUTES
803
- g += (0, tools_1.generateCustomAttributes)(this.data);
804
- // CREATED
805
- if (this.data.created) {
806
- g += 'CREATED:' + (0, tools_1.formatDate)(this.calendar.timezone(), this.data.created) + '\r\n';
807
- }
808
- // LAST-MODIFIED
809
- if (this.data.lastModified) {
810
- g += 'LAST-MODIFIED:' + (0, tools_1.formatDate)(this.calendar.timezone(), this.data.lastModified) + '\r\n';
811
- }
812
- if (this.data.class) {
813
- g += 'CLASS:' + this.data.class.toUpperCase() + '\r\n';
814
- }
815
- g += 'END:VEVENT\r\n';
816
- return g;
817
- }
818
- }
819
- exports.default = ICalEvent;
820
- //# sourceMappingURL=event.js.map