ical-generator 5.0.2-develop.2 → 6.0.0-develop.1
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/README.md +14 -20
- package/dist/index.cjs +24 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -115
- package/dist/index.d.ts +52 -115
- package/dist/index.js +26 -26
- package/dist/index.js.map +1 -1
- package/package.json +8 -14
- package/src/alarm.ts +68 -113
- package/src/attendee.ts +14 -11
- package/src/calendar.ts +0 -88
- package/src/category.ts +14 -12
- package/src/event.ts +13 -17
- package/src/index.ts +3 -1
- package/src/tools.ts +3 -1
package/package.json
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Sebastian Pekarek <mail@sebbo.net>",
|
|
3
|
-
"browser": {
|
|
4
|
-
"fs": false
|
|
5
|
-
},
|
|
6
3
|
"bugs": {
|
|
7
4
|
"url": "http://github.com/sebbo2002/ical-generator/issues"
|
|
8
5
|
},
|
|
@@ -15,17 +12,16 @@
|
|
|
15
12
|
"@semantic-release/changelog": "^6.0.3",
|
|
16
13
|
"@semantic-release/exec": "^6.0.3",
|
|
17
14
|
"@semantic-release/git": "^10.0.1",
|
|
18
|
-
"@semantic-release/npm": "^
|
|
15
|
+
"@semantic-release/npm": "^11.0.0",
|
|
19
16
|
"@touch4it/ical-timezones": "^1.9.0",
|
|
20
17
|
"@types/luxon": "^3.3.2",
|
|
21
|
-
"@types/mocha": "^10.0.
|
|
22
|
-
"@types/node": "^20.5.8",
|
|
18
|
+
"@types/mocha": "^10.0.2",
|
|
23
19
|
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
24
20
|
"@typescript-eslint/parser": "^6.7.0",
|
|
25
21
|
"c8": "^8.0.1",
|
|
26
|
-
"dayjs": "^1.11.
|
|
27
|
-
"eslint": "^8.
|
|
28
|
-
"eslint-plugin-jsonc": "^2.
|
|
22
|
+
"dayjs": "^1.11.10",
|
|
23
|
+
"eslint": "^8.51.0",
|
|
24
|
+
"eslint-plugin-jsonc": "^2.10.0",
|
|
29
25
|
"esm": "^3.2.25",
|
|
30
26
|
"license-checker": "^25.0.1",
|
|
31
27
|
"luxon": "^3.4.3",
|
|
@@ -34,14 +30,13 @@
|
|
|
34
30
|
"moment": "^2.29.4",
|
|
35
31
|
"moment-timezone": "^0.5.43",
|
|
36
32
|
"nyc": "^15.1.0",
|
|
37
|
-
"portfinder": "^1.0.32",
|
|
38
33
|
"rrule": "^2.7.2",
|
|
39
|
-
"semantic-release": "^
|
|
34
|
+
"semantic-release": "^22.0.5",
|
|
40
35
|
"semantic-release-license": "^1.0.2",
|
|
41
36
|
"source-map-support": "^0.5.21",
|
|
42
37
|
"ts-node": "^10.9.1",
|
|
43
38
|
"tsup": "^7.2.0",
|
|
44
|
-
"typedoc": "^0.25.
|
|
39
|
+
"typedoc": "^0.25.2",
|
|
45
40
|
"typescript": "^5.2.2"
|
|
46
41
|
},
|
|
47
42
|
"engines": {
|
|
@@ -77,7 +72,6 @@
|
|
|
77
72
|
"@touch4it/ical-timezones": ">=1.6.0",
|
|
78
73
|
"@types/luxon": ">= 1.26.0",
|
|
79
74
|
"@types/mocha": ">= 8.2.1",
|
|
80
|
-
"@types/node": ">= 15.0.0",
|
|
81
75
|
"dayjs": ">= 1.10.0",
|
|
82
76
|
"luxon": ">= 1.26.0",
|
|
83
77
|
"moment": ">= 2.29.0",
|
|
@@ -131,5 +125,5 @@
|
|
|
131
125
|
"test": "mocha"
|
|
132
126
|
},
|
|
133
127
|
"type": "module",
|
|
134
|
-
"version": "
|
|
128
|
+
"version": "6.0.0-develop.1"
|
|
135
129
|
}
|
package/src/alarm.ts
CHANGED
|
@@ -32,24 +32,34 @@ export interface ICalAttachment {
|
|
|
32
32
|
mime: string | null;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
export type ICalAlarmData = ICalAlarmBaseData |
|
|
36
|
+
ICalAlarmTriggerData |
|
|
37
|
+
ICalAlarmTriggerAfterData |
|
|
38
|
+
ICalAlarmTriggerBeforeData;
|
|
39
|
+
|
|
40
|
+
type ICalAlarmTriggerData = ICalAlarmBaseData & { trigger: number | ICalDateTimeValue };
|
|
41
|
+
type ICalAlarmTriggerAfterData = ICalAlarmBaseData & { triggerAfter: number | ICalDateTimeValue };
|
|
42
|
+
type ICalAlarmTriggerBeforeData = ICalAlarmBaseData & { triggerBefore: number | ICalDateTimeValue };
|
|
43
|
+
|
|
44
|
+
interface ICalAlarmBaseData {
|
|
45
|
+
type?: ICalAlarmType;
|
|
38
46
|
relatesTo?: ICalAlarmRelatesTo | null;
|
|
39
|
-
|
|
40
|
-
triggerAfter?: number | ICalDateTimeValue | null;
|
|
41
|
-
repeat?: number | null;
|
|
42
|
-
interval?: number | null;
|
|
47
|
+
repeat?: ICalAlarmRepeatData | null;
|
|
43
48
|
attach?: string | ICalAttachment | null;
|
|
44
49
|
description?: string | null;
|
|
45
50
|
x?: {key: string, value: string}[] | [string, string][] | Record<string, string>;
|
|
46
51
|
}
|
|
47
52
|
|
|
53
|
+
export interface ICalAlarmRepeatData {
|
|
54
|
+
times: number;
|
|
55
|
+
interval: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
interface ICalInternalAlarmData {
|
|
49
|
-
type: ICalAlarmType
|
|
50
|
-
trigger: ICalDateTimeValue | number
|
|
59
|
+
type: ICalAlarmType;
|
|
60
|
+
trigger: ICalDateTimeValue | number;
|
|
51
61
|
relatesTo: ICalAlarmRelatesTo | null;
|
|
52
|
-
repeat:
|
|
62
|
+
repeat: ICalAlarmRepeatData | null;
|
|
53
63
|
interval: number | null;
|
|
54
64
|
attach: ICalAttachment | null;
|
|
55
65
|
description: string | null;
|
|
@@ -57,10 +67,10 @@ interface ICalInternalAlarmData {
|
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
export interface ICalAlarmJSONData {
|
|
60
|
-
type: ICalAlarmType
|
|
61
|
-
trigger: string | number
|
|
70
|
+
type: ICalAlarmType;
|
|
71
|
+
trigger: string | number;
|
|
62
72
|
relatesTo: ICalAlarmRelatesTo | null;
|
|
63
|
-
repeat:
|
|
73
|
+
repeat: ICalAlarmRepeatData | null;
|
|
64
74
|
interval: number | null;
|
|
65
75
|
attach: ICalAttachment | null;
|
|
66
76
|
description: string | null;
|
|
@@ -99,8 +109,8 @@ export default class ICalAlarm {
|
|
|
99
109
|
*/
|
|
100
110
|
constructor (data: ICalAlarmData, event: ICalEvent) {
|
|
101
111
|
this.data = {
|
|
102
|
-
type:
|
|
103
|
-
trigger:
|
|
112
|
+
type: ICalAlarmType.display,
|
|
113
|
+
trigger: -600,
|
|
104
114
|
relatesTo: null,
|
|
105
115
|
repeat: null,
|
|
106
116
|
interval: null,
|
|
@@ -115,11 +125,10 @@ export default class ICalAlarm {
|
|
|
115
125
|
}
|
|
116
126
|
|
|
117
127
|
data.type !== undefined && this.type(data.type);
|
|
118
|
-
data.trigger !== undefined && this.trigger(data.trigger);
|
|
119
|
-
data.triggerBefore !== undefined && this.triggerBefore(data.triggerBefore);
|
|
120
|
-
data.triggerAfter !== undefined && this.triggerAfter(data.triggerAfter);
|
|
121
|
-
data.repeat
|
|
122
|
-
data.interval !== undefined && this.interval(data.interval);
|
|
128
|
+
'trigger' in data && data.trigger !== undefined && this.trigger(data.trigger);
|
|
129
|
+
'triggerBefore' in data && data.triggerBefore !== undefined && this.triggerBefore(data.triggerBefore);
|
|
130
|
+
'triggerAfter' in data && data.triggerAfter !== undefined && this.triggerAfter(data.triggerAfter);
|
|
131
|
+
data.repeat && this.repeat(data.repeat);
|
|
123
132
|
data.attach !== undefined && this.attach(data.attach);
|
|
124
133
|
data.description !== undefined && this.description(data.description);
|
|
125
134
|
data.x !== undefined && this.x(data.x);
|
|
@@ -130,24 +139,19 @@ export default class ICalAlarm {
|
|
|
130
139
|
* Get the alarm type
|
|
131
140
|
* @since 0.2.1
|
|
132
141
|
*/
|
|
133
|
-
type (type: ICalAlarmType
|
|
142
|
+
type (type: ICalAlarmType): this;
|
|
134
143
|
|
|
135
144
|
/**
|
|
136
145
|
* Set the alarm type. See [[`ICalAlarmType`]]
|
|
137
146
|
* for available status options.
|
|
138
147
|
* @since 0.2.1
|
|
139
148
|
*/
|
|
140
|
-
type (): ICalAlarmType
|
|
141
|
-
type (type?: ICalAlarmType
|
|
149
|
+
type (): ICalAlarmType;
|
|
150
|
+
type (type?: ICalAlarmType): this | ICalAlarmType {
|
|
142
151
|
if (type === undefined) {
|
|
143
152
|
return this.data.type;
|
|
144
153
|
}
|
|
145
|
-
if (!type) {
|
|
146
|
-
this.data.type = null;
|
|
147
|
-
return this;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (!Object.keys(ICalAlarmType).includes(type)) {
|
|
154
|
+
if (!type || !Object.keys(ICalAlarmType).includes(type)) {
|
|
151
155
|
throw new Error('`type` is not correct, must be either `display` or `audio`!');
|
|
152
156
|
}
|
|
153
157
|
|
|
@@ -165,7 +169,7 @@ export default class ICalAlarm {
|
|
|
165
169
|
*
|
|
166
170
|
* @since 0.2.1
|
|
167
171
|
*/
|
|
168
|
-
trigger (): number | ICalDateTimeValue
|
|
172
|
+
trigger (): number | ICalDateTimeValue;
|
|
169
173
|
|
|
170
174
|
/**
|
|
171
175
|
* Use this method to set the alarm time.
|
|
@@ -185,28 +189,22 @@ export default class ICalAlarm {
|
|
|
185
189
|
*
|
|
186
190
|
* @since 0.2.1
|
|
187
191
|
*/
|
|
188
|
-
trigger (trigger: number | ICalDateTimeValue | Date
|
|
189
|
-
trigger (trigger?: number | ICalDateTimeValue | Date
|
|
192
|
+
trigger (trigger: number | ICalDateTimeValue | Date): this;
|
|
193
|
+
trigger (trigger?: number | ICalDateTimeValue | Date): this | number | ICalDateTimeValue {
|
|
190
194
|
|
|
191
195
|
// Getter
|
|
192
196
|
if (trigger === undefined && typeof this.data.trigger === 'number') {
|
|
193
197
|
return -1 * this.data.trigger;
|
|
194
198
|
}
|
|
195
|
-
if (trigger === undefined && this.data.trigger) {
|
|
196
|
-
return this.data.trigger;
|
|
197
|
-
}
|
|
198
199
|
if (trigger === undefined) {
|
|
199
|
-
return
|
|
200
|
+
return this.data.trigger;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
// Setter
|
|
203
|
-
if (
|
|
204
|
-
this.data.trigger = null;
|
|
205
|
-
}
|
|
206
|
-
else if (typeof trigger === 'number' && isFinite(trigger)) {
|
|
204
|
+
if (typeof trigger === 'number' && isFinite(trigger)) {
|
|
207
205
|
this.data.trigger = -1 * trigger;
|
|
208
206
|
}
|
|
209
|
-
else if(typeof trigger === 'number') {
|
|
207
|
+
else if(!trigger || typeof trigger === 'number') {
|
|
210
208
|
throw new Error('`trigger` is not correct, must be a finite number or a supported date!');
|
|
211
209
|
}
|
|
212
210
|
else {
|
|
@@ -275,7 +273,7 @@ export default class ICalAlarm {
|
|
|
275
273
|
*
|
|
276
274
|
* @since 0.2.1
|
|
277
275
|
*/
|
|
278
|
-
triggerAfter (): number | ICalDateTimeValue
|
|
276
|
+
triggerAfter (): number | ICalDateTimeValue;
|
|
279
277
|
|
|
280
278
|
/**
|
|
281
279
|
* Use this method to set the alarm time. Unlike `trigger`, this time
|
|
@@ -295,8 +293,8 @@ export default class ICalAlarm {
|
|
|
295
293
|
*
|
|
296
294
|
* @since 0.2.1
|
|
297
295
|
*/
|
|
298
|
-
triggerAfter (trigger: number | ICalDateTimeValue
|
|
299
|
-
triggerAfter (trigger?: number | ICalDateTimeValue
|
|
296
|
+
triggerAfter (trigger: number | ICalDateTimeValue): this;
|
|
297
|
+
triggerAfter (trigger?: number | ICalDateTimeValue): this | number | ICalDateTimeValue {
|
|
300
298
|
if (trigger === undefined) {
|
|
301
299
|
return this.data.trigger;
|
|
302
300
|
}
|
|
@@ -315,7 +313,7 @@ export default class ICalAlarm {
|
|
|
315
313
|
* @since 0.2.1
|
|
316
314
|
* @alias trigger
|
|
317
315
|
*/
|
|
318
|
-
triggerBefore (trigger: number | ICalDateTimeValue
|
|
316
|
+
triggerBefore (trigger: number | ICalDateTimeValue): this;
|
|
319
317
|
|
|
320
318
|
/**
|
|
321
319
|
* Use this method to set the alarm time.
|
|
@@ -336,8 +334,8 @@ export default class ICalAlarm {
|
|
|
336
334
|
* @since 0.2.1
|
|
337
335
|
* @alias trigger
|
|
338
336
|
*/
|
|
339
|
-
triggerBefore (): number | ICalDateTimeValue
|
|
340
|
-
triggerBefore (trigger?: number | ICalDateTimeValue
|
|
337
|
+
triggerBefore (): number | ICalDateTimeValue;
|
|
338
|
+
triggerBefore (trigger?: number | ICalDateTimeValue): this | number | ICalDateTimeValue {
|
|
341
339
|
if(trigger === undefined) {
|
|
342
340
|
return this.trigger();
|
|
343
341
|
}
|
|
@@ -350,7 +348,7 @@ export default class ICalAlarm {
|
|
|
350
348
|
* Get Alarm Repetitions
|
|
351
349
|
* @since 0.2.1
|
|
352
350
|
*/
|
|
353
|
-
repeat():
|
|
351
|
+
repeat(): ICalAlarmRepeatData | null;
|
|
354
352
|
|
|
355
353
|
/**
|
|
356
354
|
* Set Alarm Repetitions. Use this to repeat the alarm.
|
|
@@ -361,15 +359,17 @@ export default class ICalAlarm {
|
|
|
361
359
|
*
|
|
362
360
|
* // repeat the alarm 4 times every 5 minutes…
|
|
363
361
|
* cal.createAlarm({
|
|
364
|
-
* repeat:
|
|
365
|
-
*
|
|
362
|
+
* repeat: {
|
|
363
|
+
* times: 4,
|
|
364
|
+
* interval: 300
|
|
365
|
+
* }
|
|
366
366
|
* });
|
|
367
367
|
* ```
|
|
368
368
|
*
|
|
369
369
|
* @since 0.2.1
|
|
370
370
|
*/
|
|
371
|
-
repeat(repeat:
|
|
372
|
-
repeat (repeat?:
|
|
371
|
+
repeat(repeat: ICalAlarmRepeatData | null): this;
|
|
372
|
+
repeat (repeat?: ICalAlarmRepeatData | null): this | ICalAlarmRepeatData | null {
|
|
373
373
|
if (repeat === undefined) {
|
|
374
374
|
return this.data.repeat;
|
|
375
375
|
}
|
|
@@ -378,52 +378,17 @@ export default class ICalAlarm {
|
|
|
378
378
|
return this;
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
-
if (typeof repeat !== '
|
|
382
|
-
throw new Error('`repeat` is not correct, must be
|
|
381
|
+
if (typeof repeat !== 'object') {
|
|
382
|
+
throw new Error('`repeat` is not correct, must be an object!');
|
|
383
383
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
return this;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Get Repeat Interval
|
|
392
|
-
* @since 0.2.1
|
|
393
|
-
*/
|
|
394
|
-
interval (interval: number | null): this;
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Set Repeat Interval
|
|
398
|
-
*
|
|
399
|
-
* ```javascript
|
|
400
|
-
* const cal = ical();
|
|
401
|
-
* const event = cal.createEvent();
|
|
402
|
-
*
|
|
403
|
-
* // repeat the alarm 4 times every 5 minutes…
|
|
404
|
-
* cal.createAlarm({
|
|
405
|
-
* repeat: 4,
|
|
406
|
-
* interval: 300
|
|
407
|
-
* });
|
|
408
|
-
* ```
|
|
409
|
-
*
|
|
410
|
-
* @since 0.2.1
|
|
411
|
-
*/
|
|
412
|
-
interval(): number | null;
|
|
413
|
-
interval (interval?: number | null): this | number | null {
|
|
414
|
-
if (interval === undefined) {
|
|
415
|
-
return this.data.interval || null;
|
|
384
|
+
if (typeof repeat.times !== 'number' || !isFinite(repeat.times)) {
|
|
385
|
+
throw new Error('`repeat.times` is not correct, must be numeric!');
|
|
416
386
|
}
|
|
417
|
-
if (!interval) {
|
|
418
|
-
|
|
419
|
-
return this;
|
|
387
|
+
if (typeof repeat.interval !== 'number' || !isFinite(repeat.interval)) {
|
|
388
|
+
throw new Error('`repeat.interval` is not correct, must be numeric!');
|
|
420
389
|
}
|
|
421
390
|
|
|
422
|
-
|
|
423
|
-
throw new Error('`interval` is not correct, must be numeric!');
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
this.data.interval = interval;
|
|
391
|
+
this.data.repeat = repeat;
|
|
427
392
|
return this;
|
|
428
393
|
}
|
|
429
394
|
|
|
@@ -619,13 +584,6 @@ export default class ICalAlarm {
|
|
|
619
584
|
toString (): string {
|
|
620
585
|
let g = 'BEGIN:VALARM\r\n';
|
|
621
586
|
|
|
622
|
-
if (!this.data.type) {
|
|
623
|
-
throw new Error('No value for `type` in ICalAlarm given!');
|
|
624
|
-
}
|
|
625
|
-
if (!this.data.trigger) {
|
|
626
|
-
throw new Error('No value for `trigger` in ICalAlarm given!');
|
|
627
|
-
}
|
|
628
|
-
|
|
629
587
|
// ACTION
|
|
630
588
|
g += 'ACTION:' + this.data.type.toUpperCase() + '\r\n';
|
|
631
589
|
|
|
@@ -638,26 +596,23 @@ export default class ICalAlarm {
|
|
|
638
596
|
}
|
|
639
597
|
}
|
|
640
598
|
else if (typeof this.data.trigger === 'number') {
|
|
641
|
-
g += 'TRIGGER;RELATED=' + this.data.relatesTo
|
|
599
|
+
g += 'TRIGGER;RELATED=' + this.data.relatesTo?.toUpperCase() + ':' + toDurationString(this.data.trigger) + '\r\n';
|
|
642
600
|
}
|
|
643
601
|
else {
|
|
644
602
|
g += 'TRIGGER;VALUE=DATE-TIME:' + formatDate(this.event.timezone(), this.data.trigger) + '\r\n';
|
|
645
603
|
}
|
|
646
604
|
|
|
647
605
|
// REPEAT
|
|
648
|
-
if (this.data.repeat && !this.data.interval) {
|
|
649
|
-
throw new Error('No value for `interval` in ICalAlarm given, but required for `repeat`!');
|
|
650
|
-
}
|
|
651
606
|
if (this.data.repeat) {
|
|
652
|
-
|
|
653
|
-
|
|
607
|
+
if (!this.data.repeat.times) {
|
|
608
|
+
throw new Error('No value for `repeat.times` in ICalAlarm given, but required for `interval`!');
|
|
609
|
+
}
|
|
610
|
+
if (!this.data.repeat.interval) {
|
|
611
|
+
throw new Error('No value for `repeat.interval` in ICalAlarm given, but required for `repeat`!');
|
|
612
|
+
}
|
|
654
613
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
throw new Error('No value for `repeat` in ICalAlarm given, but required for `interval`!');
|
|
658
|
-
}
|
|
659
|
-
if (this.data.interval) {
|
|
660
|
-
g += 'DURATION:' + toDurationString(this.data.interval) + '\r\n';
|
|
614
|
+
g += 'REPEAT:' + this.data.repeat.times + '\r\n';
|
|
615
|
+
g += 'DURATION:' + toDurationString(this.data.repeat.interval) + '\r\n';
|
|
661
616
|
}
|
|
662
617
|
|
|
663
618
|
// ATTACH
|
package/src/attendee.ts
CHANGED
|
@@ -7,7 +7,7 @@ import ICalEvent from './event.js';
|
|
|
7
7
|
|
|
8
8
|
interface ICalInternalAttendeeData {
|
|
9
9
|
name: string | null;
|
|
10
|
-
email: string
|
|
10
|
+
email: string;
|
|
11
11
|
mailto: string | null;
|
|
12
12
|
sentBy: string | null;
|
|
13
13
|
status: ICalAttendeeStatus | null;
|
|
@@ -21,7 +21,7 @@ interface ICalInternalAttendeeData {
|
|
|
21
21
|
|
|
22
22
|
export interface ICalAttendeeData {
|
|
23
23
|
name?: string | null;
|
|
24
|
-
email
|
|
24
|
+
email: string;
|
|
25
25
|
mailto?: string | null;
|
|
26
26
|
sentBy?: string | null;
|
|
27
27
|
status?: ICalAttendeeStatus | null;
|
|
@@ -37,7 +37,7 @@ export interface ICalAttendeeData {
|
|
|
37
37
|
|
|
38
38
|
export interface ICalAttendeeJSONData {
|
|
39
39
|
name: string | null;
|
|
40
|
-
email: string
|
|
40
|
+
email: string;
|
|
41
41
|
mailto: string | null;
|
|
42
42
|
sentBy: string | null;
|
|
43
43
|
status: ICalAttendeeStatus | null;
|
|
@@ -81,14 +81,14 @@ export enum ICalAttendeeType {
|
|
|
81
81
|
* import ical from 'ical-generator';
|
|
82
82
|
* const calendar = ical();
|
|
83
83
|
* const event = calendar.createEvent();
|
|
84
|
-
* const attendee = event.createAttendee();
|
|
84
|
+
* const attendee = event.createAttendee({ email: 'mail@example.com' });
|
|
85
85
|
* ```
|
|
86
86
|
*
|
|
87
87
|
* You can also use the [[`ICalAttendee`]] object directly:
|
|
88
88
|
*
|
|
89
89
|
* ```javascript
|
|
90
90
|
* import ical, {ICalAttendee} from 'ical-generator';
|
|
91
|
-
* const attendee = new ICalAttendee();
|
|
91
|
+
* const attendee = new ICalAttendee({ email: 'mail@example.com' });
|
|
92
92
|
* event.attendees([attendee]);
|
|
93
93
|
* ```
|
|
94
94
|
*/
|
|
@@ -106,7 +106,7 @@ export default class ICalAttendee {
|
|
|
106
106
|
constructor(data: ICalAttendeeData, event: ICalEvent) {
|
|
107
107
|
this.data = {
|
|
108
108
|
name: null,
|
|
109
|
-
email:
|
|
109
|
+
email: '',
|
|
110
110
|
mailto: null,
|
|
111
111
|
sentBy: null,
|
|
112
112
|
status: null,
|
|
@@ -121,6 +121,9 @@ export default class ICalAttendee {
|
|
|
121
121
|
if (!this.event) {
|
|
122
122
|
throw new Error('`event` option required!');
|
|
123
123
|
}
|
|
124
|
+
if (!data.email) {
|
|
125
|
+
throw new Error('No value for `email` in ICalAttendee given!');
|
|
126
|
+
}
|
|
124
127
|
|
|
125
128
|
data.name !== undefined && this.name(data.name);
|
|
126
129
|
data.email !== undefined && this.email(data.email);
|
|
@@ -163,14 +166,14 @@ export default class ICalAttendee {
|
|
|
163
166
|
* Get the attendee's email address
|
|
164
167
|
* @since 0.2.0
|
|
165
168
|
*/
|
|
166
|
-
email(): string
|
|
169
|
+
email(): string;
|
|
167
170
|
|
|
168
171
|
/**
|
|
169
172
|
* Set the attendee's email address
|
|
170
173
|
* @since 0.2.0
|
|
171
174
|
*/
|
|
172
|
-
email(email: string
|
|
173
|
-
email(email?: string
|
|
175
|
+
email(email: string): this;
|
|
176
|
+
email(email?: string): this | string {
|
|
174
177
|
if (!email) {
|
|
175
178
|
return this.data.email;
|
|
176
179
|
}
|
|
@@ -363,7 +366,7 @@ export default class ICalAttendee {
|
|
|
363
366
|
|
|
364
367
|
if(typeof delegatedTo === 'string') {
|
|
365
368
|
this.data.delegatedTo = new ICalAttendee(
|
|
366
|
-
checkNameAndMail('delegatedTo', delegatedTo),
|
|
369
|
+
{ email: delegatedTo, ...checkNameAndMail('delegatedTo', delegatedTo) },
|
|
367
370
|
this.event,
|
|
368
371
|
);
|
|
369
372
|
}
|
|
@@ -405,7 +408,7 @@ export default class ICalAttendee {
|
|
|
405
408
|
}
|
|
406
409
|
else if(typeof delegatedFrom === 'string') {
|
|
407
410
|
this.data.delegatedFrom = new ICalAttendee(
|
|
408
|
-
checkNameAndMail('delegatedFrom', delegatedFrom),
|
|
411
|
+
{ email: delegatedFrom, ...checkNameAndMail('delegatedFrom', delegatedFrom) },
|
|
409
412
|
this.event,
|
|
410
413
|
);
|
|
411
414
|
}
|
package/src/calendar.ts
CHANGED
|
@@ -9,8 +9,6 @@ import {
|
|
|
9
9
|
toDurationString
|
|
10
10
|
} from './tools.js';
|
|
11
11
|
import ICalEvent, {ICalEventData, ICalEventJSONData} from './event.js';
|
|
12
|
-
import {writeFile, writeFileSync, promises as fsPromises} from 'node:fs';
|
|
13
|
-
import {ServerResponse} from 'node:http';
|
|
14
12
|
import { ICalMomentDurationStub, ICalTimezone } from './types.js';
|
|
15
13
|
|
|
16
14
|
|
|
@@ -583,92 +581,6 @@ export default class ICalCalendar {
|
|
|
583
581
|
}
|
|
584
582
|
|
|
585
583
|
|
|
586
|
-
/**
|
|
587
|
-
* Save ical file using [`fs/promises`](https://nodejs.org/api/fs.html#fs_fspromises_writefile_file_data_options).
|
|
588
|
-
* Only works in node.js environments.
|
|
589
|
-
*
|
|
590
|
-
* ```javascript
|
|
591
|
-
* await calendar.save('./calendar.ical');
|
|
592
|
-
* ```
|
|
593
|
-
*/
|
|
594
|
-
save(path: string): Promise<void>;
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* Save ical file with [`fs.writeFile`](http://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback).
|
|
598
|
-
* Only works in node.js environments.
|
|
599
|
-
*
|
|
600
|
-
* ```javascript
|
|
601
|
-
* calendar.save('./calendar.ical', err => {
|
|
602
|
-
* console.log(err);
|
|
603
|
-
* });
|
|
604
|
-
* ```
|
|
605
|
-
*/
|
|
606
|
-
save(path: string, cb?: (err: NodeJS.ErrnoException | null) => void): this;
|
|
607
|
-
save(path: string, cb?: (err: NodeJS.ErrnoException | null) => void): this | Promise<void> {
|
|
608
|
-
if (cb) {
|
|
609
|
-
writeFile(path, this.toString(), cb);
|
|
610
|
-
return this;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
return fsPromises.writeFile(path, this.toString());
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
/**
|
|
618
|
-
* Save Calendar to disk synchronously using
|
|
619
|
-
* [fs.writeFileSync](http://nodejs.org/api/fs.html#fs_fs_writefilesync_filename_data_options).
|
|
620
|
-
* Only works in node.js environments.
|
|
621
|
-
*
|
|
622
|
-
* ```javascript
|
|
623
|
-
* calendar.saveSync('./calendar.ical');
|
|
624
|
-
* ```
|
|
625
|
-
*/
|
|
626
|
-
saveSync(path: string): this {
|
|
627
|
-
writeFileSync(path, this.toString());
|
|
628
|
-
return this;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
/**
|
|
633
|
-
* Send calendar to the user when using HTTP using the passed `ServerResponse` object.
|
|
634
|
-
* Use second parameter `filename` to change the filename, which defaults to `'calendar.ics'`.
|
|
635
|
-
*
|
|
636
|
-
* @param response HTTP Response object which is used to send the calendar
|
|
637
|
-
* @param [filename = 'calendar.ics'] Filename of the calendar file
|
|
638
|
-
*/
|
|
639
|
-
serve(response: ServerResponse, filename = 'calendar.ics'): this {
|
|
640
|
-
response.writeHead(200, {
|
|
641
|
-
'Content-Type': 'text/calendar; charset=utf-8',
|
|
642
|
-
'Content-Disposition': `attachment; filename="${filename}"`
|
|
643
|
-
});
|
|
644
|
-
|
|
645
|
-
response.end(this.toString());
|
|
646
|
-
return this;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* Generates a blob to use for downloads or to generate a download URL.
|
|
652
|
-
* Only supported in browsers supporting the Blob API.
|
|
653
|
-
*
|
|
654
|
-
* @since 1.9.0
|
|
655
|
-
*/
|
|
656
|
-
toBlob(): Blob {
|
|
657
|
-
return new Blob([this.toString()], {type: 'text/calendar'});
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* Returns a URL to download the ical file. Uses the Blob object internally,
|
|
663
|
-
* so it's only supported in browsers supporting the Blob API.
|
|
664
|
-
*
|
|
665
|
-
* @since 1.9.0
|
|
666
|
-
*/
|
|
667
|
-
toURL(): string {
|
|
668
|
-
return URL.createObjectURL(this.toBlob());
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
|
|
672
584
|
/**
|
|
673
585
|
* Set X-* attributes. Woun't filter double attributes,
|
|
674
586
|
* which are also added by another method (e.g. busystatus),
|
package/src/category.ts
CHANGED
|
@@ -5,13 +5,15 @@ import {escape} from './tools.js';
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export interface ICalCategoryData {
|
|
8
|
-
name
|
|
8
|
+
name: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface ICalCategoryInternalData {
|
|
12
|
-
name: string
|
|
12
|
+
name: string;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
export type ICalCategoryJSONData = ICalCategoryInternalData;
|
|
16
|
+
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Usually you get an `ICalCategory` object like this:
|
|
@@ -40,10 +42,14 @@ export default class ICalCategory {
|
|
|
40
42
|
*/
|
|
41
43
|
constructor(data: ICalCategoryData) {
|
|
42
44
|
this.data = {
|
|
43
|
-
name:
|
|
45
|
+
name: ''
|
|
44
46
|
};
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
if(!data.name) {
|
|
49
|
+
throw new Error('No value for `name` in ICalCategory given!');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.name(data.name);
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
|
|
@@ -51,19 +57,19 @@ export default class ICalCategory {
|
|
|
51
57
|
* Get the category name
|
|
52
58
|
* @since 0.3.0
|
|
53
59
|
*/
|
|
54
|
-
name(): string
|
|
60
|
+
name(): string;
|
|
55
61
|
|
|
56
62
|
/**
|
|
57
63
|
* Set the category name
|
|
58
64
|
* @since 0.3.0
|
|
59
65
|
*/
|
|
60
|
-
name(name: string
|
|
61
|
-
name(name?: string
|
|
66
|
+
name(name: string): this;
|
|
67
|
+
name(name?: string): this | string {
|
|
62
68
|
if (name === undefined) {
|
|
63
69
|
return this.data.name;
|
|
64
70
|
}
|
|
65
71
|
|
|
66
|
-
this.data.name = name
|
|
72
|
+
this.data.name = name;
|
|
67
73
|
return this;
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -89,10 +95,6 @@ export default class ICalCategory {
|
|
|
89
95
|
toString(): string {
|
|
90
96
|
|
|
91
97
|
// CN / Name
|
|
92
|
-
if (!this.data.name) {
|
|
93
|
-
throw new Error('No value for `name` in ICalCategory given!');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
98
|
return escape(this.data.name, false);
|
|
97
99
|
}
|
|
98
100
|
}
|