ical-generator 7.0.0-develop.2 → 7.0.0-develop.3

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/package.json CHANGED
@@ -125,5 +125,5 @@
125
125
  "test": "mocha"
126
126
  },
127
127
  "type": "module",
128
- "version": "7.0.0-develop.2"
128
+ "version": "7.0.0-develop.3"
129
129
  }
package/src/alarm.ts CHANGED
@@ -8,14 +8,17 @@ import {
8
8
  generateCustomAttributes,
9
9
  checkDate,
10
10
  toDurationString,
11
- toJSON
11
+ toJSON,
12
+ checkNameAndMail
12
13
  } from './tools.js';
13
14
  import {ICalDateTimeValue} from './types.js';
15
+ import ICalAttendee, { ICalAttendeeData } from './attendee.js';
14
16
 
15
17
 
16
18
  export enum ICalAlarmType {
17
19
  display = 'display',
18
- audio = 'audio'
20
+ audio = 'audio',
21
+ email = 'email'
19
22
  }
20
23
 
21
24
  export const ICalAlarmRelatesTo = {
@@ -47,6 +50,8 @@ export interface ICalAlarmBaseData {
47
50
  repeat?: ICalAlarmRepeatData | null;
48
51
  attach?: string | ICalAttachment | null;
49
52
  description?: string | null;
53
+ summary?: string | null;
54
+ attendees?: ICalAttendee[] | ICalAttendeeData[];
50
55
  x?: {key: string, value: string}[] | [string, string][] | Record<string, string>;
51
56
  }
52
57
 
@@ -63,6 +68,8 @@ interface ICalInternalAlarmData {
63
68
  interval: number | null;
64
69
  attach: ICalAttachment | null;
65
70
  description: string | null;
71
+ summary: string | null;
72
+ attendees: ICalAttendee[];
66
73
  x: [string, string][];
67
74
  }
68
75
 
@@ -74,6 +81,8 @@ export interface ICalAlarmJSONData {
74
81
  interval: number | null;
75
82
  attach: ICalAttachment | null;
76
83
  description: string | null;
84
+ summary: string | null;
85
+ attendees: ICalAttendee[];
77
86
  x: {key: string, value: string}[];
78
87
  }
79
88
 
@@ -116,6 +125,8 @@ export default class ICalAlarm {
116
125
  interval: null,
117
126
  attach: null,
118
127
  description: null,
128
+ summary: null,
129
+ attendees: [],
119
130
  x: []
120
131
  };
121
132
 
@@ -131,6 +142,8 @@ export default class ICalAlarm {
131
142
  data.repeat && this.repeat(data.repeat);
132
143
  data.attach !== undefined && this.attach(data.attach);
133
144
  data.description !== undefined && this.description(data.description);
145
+ data.summary !== undefined && this.summary(data.summary);
146
+ data.attendees !== undefined && this.attendees(data.attendees);
134
147
  data.x !== undefined && this.x(data.x);
135
148
  }
136
149
 
@@ -467,7 +480,8 @@ export default class ICalAlarm {
467
480
 
468
481
  /**
469
482
  * Get the alarm description. Used to set the alarm message
470
- * if alarm type is display. Defaults to the event's summary.
483
+ * if alarm type is `display`. If the alarm type is `email`, it's
484
+ * used to set the email body. Defaults to the event's summary.
471
485
  *
472
486
  * @since 0.2.1
473
487
  */
@@ -475,7 +489,8 @@ export default class ICalAlarm {
475
489
 
476
490
  /**
477
491
  * Set the alarm description. Used to set the alarm message
478
- * if alarm type is display. Defaults to the event's summary.
492
+ * if alarm type is `display`. If the alarm type is `email`, it's
493
+ * used to set the email body. Defaults to the event's summary.
479
494
  *
480
495
  * @since 0.2.1
481
496
  */
@@ -494,6 +509,79 @@ export default class ICalAlarm {
494
509
  }
495
510
 
496
511
 
512
+ /**
513
+ * Get the alarm summary. Used to set the email subject
514
+ * if alarm type is `email`. Defaults to the event's summary.
515
+ *
516
+ * @since 7.0.0
517
+ */
518
+ summary (): string | null;
519
+
520
+ /**
521
+ * Set the alarm summary. Used to set the email subject
522
+ * if alarm type is display. Defaults to the event's summary.
523
+ *
524
+ * @since 0.2.1
525
+ */
526
+ summary (summary: string | null): this;
527
+ summary (summary?: string | null): this | string | null {
528
+ if (summary === undefined) {
529
+ return this.data.summary;
530
+ }
531
+ if (!summary) {
532
+ this.data.summary = null;
533
+ return this;
534
+ }
535
+
536
+ this.data.summary = summary;
537
+ return this;
538
+ }
539
+
540
+
541
+ /**
542
+ * Creates a new {@link ICalAttendee} and returns it. Use options to prefill
543
+ * the attendee's attributes. Calling this method without options will create
544
+ * an empty attendee.
545
+ *
546
+ * @since 7.0.0
547
+ */
548
+ createAttendee(data: ICalAttendee | ICalAttendeeData | string): ICalAttendee {
549
+ if (data instanceof ICalAttendee) {
550
+ this.data.attendees.push(data);
551
+ return data;
552
+ }
553
+ if (typeof data === 'string') {
554
+ data = { email: data, ...checkNameAndMail('data', data) };
555
+ }
556
+
557
+ const attendee = new ICalAttendee(data, this);
558
+ this.data.attendees.push(attendee);
559
+ return attendee;
560
+ }
561
+
562
+
563
+ /**
564
+ * Get all attendees
565
+ * @since 7.0.0
566
+ */
567
+ attendees(): ICalAttendee[];
568
+
569
+ /**
570
+ * Add multiple attendees to your event
571
+ *
572
+ * @since 7.0.0
573
+ */
574
+ attendees(attendees: (ICalAttendee | ICalAttendeeData | string)[]): this;
575
+ attendees(attendees?: (ICalAttendee | ICalAttendeeData | string)[]): this | ICalAttendee[] {
576
+ if (!attendees) {
577
+ return this.data.attendees;
578
+ }
579
+
580
+ attendees.forEach(attendee => this.createAttendee(attendee));
581
+ return this;
582
+ }
583
+
584
+
497
585
  /**
498
586
  * Set X-* attributes. Woun't filter double attributes,
499
587
  * which are also added by another method (e.g. type),
@@ -627,13 +715,28 @@ export default class ICalAlarm {
627
715
  }
628
716
 
629
717
  // DESCRIPTION
630
- if (this.data.type === 'display' && this.data.description) {
718
+ if (this.data.type !== 'audio' && this.data.description) {
631
719
  g += 'DESCRIPTION:' + escape(this.data.description, false) + '\r\n';
632
720
  }
633
- else if (this.data.type === 'display') {
721
+ else if (this.data.type !== 'audio') {
634
722
  g += 'DESCRIPTION:' + escape(this.event.summary(), false) + '\r\n';
635
723
  }
636
724
 
725
+ // SUMMARY
726
+ if (this.data.type === 'email' && this.data.summary) {
727
+ g += 'SUMMARY:' + escape(this.data.summary, false) + '\r\n';
728
+ }
729
+ else if (this.data.type === 'email') {
730
+ g += 'SUMMARY:' + escape(this.event.summary(), false) + '\r\n';
731
+ }
732
+
733
+ // ATTENDEES
734
+ if (this.data.type === 'email') {
735
+ this.data.attendees.forEach(attendee => {
736
+ g += attendee.toString();
737
+ });
738
+ }
739
+
637
740
  // CUSTOM X ATTRIBUTES
638
741
  g += generateCustomAttributes(this.data);
639
742
 
package/src/attendee.ts CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  import {addOrGetCustomAttributes, checkEnum, checkNameAndMail, escape} from './tools.js';
5
5
  import ICalEvent from './event.js';
6
+ import ICalAlarm from './alarm.js';
6
7
 
7
8
 
8
9
  interface ICalInternalAttendeeData {
@@ -94,16 +95,16 @@ export enum ICalAttendeeType {
94
95
  */
95
96
  export default class ICalAttendee {
96
97
  private readonly data: ICalInternalAttendeeData;
97
- private readonly event: ICalEvent;
98
+ private readonly parent: ICalEvent | ICalAlarm;
98
99
 
99
100
  /**
100
101
  * Constructor of {@link ICalAttendee}. The event reference is
101
102
  * required to query the calendar's timezone when required.
102
103
  *
103
104
  * @param data Attendee Data
104
- * @param event Reference to ICalEvent object
105
+ * @param parent Reference to ICalEvent object
105
106
  */
106
- constructor(data: ICalAttendeeData, event: ICalEvent) {
107
+ constructor(data: ICalAttendeeData, parent: ICalEvent | ICalAlarm) {
107
108
  this.data = {
108
109
  name: null,
109
110
  email: '',
@@ -117,8 +118,8 @@ export default class ICalAttendee {
117
118
  delegatedFrom: null,
118
119
  x: []
119
120
  };
120
- this.event = event;
121
- if (!this.event) {
121
+ this.parent = parent;
122
+ if (!this.parent) {
122
123
  throw new Error('`event` option required!');
123
124
  }
124
125
  if (!data.email) {
@@ -367,14 +368,14 @@ export default class ICalAttendee {
367
368
  if(typeof delegatedTo === 'string') {
368
369
  this.data.delegatedTo = new ICalAttendee(
369
370
  { email: delegatedTo, ...checkNameAndMail('delegatedTo', delegatedTo) },
370
- this.event,
371
+ this.parent,
371
372
  );
372
373
  }
373
374
  else if(delegatedTo instanceof ICalAttendee) {
374
375
  this.data.delegatedTo = delegatedTo;
375
376
  }
376
377
  else {
377
- this.data.delegatedTo = new ICalAttendee(delegatedTo, this.event);
378
+ this.data.delegatedTo = new ICalAttendee(delegatedTo, this.parent);
378
379
  }
379
380
 
380
381
  this.data.status = ICalAttendeeStatus.DELEGATED;
@@ -409,14 +410,14 @@ export default class ICalAttendee {
409
410
  else if(typeof delegatedFrom === 'string') {
410
411
  this.data.delegatedFrom = new ICalAttendee(
411
412
  { email: delegatedFrom, ...checkNameAndMail('delegatedFrom', delegatedFrom) },
412
- this.event,
413
+ this.parent,
413
414
  );
414
415
  }
415
416
  else if(delegatedFrom instanceof ICalAttendee) {
416
417
  this.data.delegatedFrom = delegatedFrom;
417
418
  }
418
419
  else {
419
- this.data.delegatedFrom = new ICalAttendee(delegatedFrom, this.event);
420
+ this.data.delegatedFrom = new ICalAttendee(delegatedFrom, this.parent);
420
421
  }
421
422
 
422
423
  return this;
@@ -439,7 +440,7 @@ export default class ICalAttendee {
439
440
  * @since 0.2.0
440
441
  */
441
442
  delegatesTo (options: ICalAttendee | ICalAttendeeData | string): ICalAttendee {
442
- const a = options instanceof ICalAttendee ? options : this.event.createAttendee(options);
443
+ const a = options instanceof ICalAttendee ? options : this.parent.createAttendee(options);
443
444
  this.delegatedTo(a);
444
445
  a.delegatedFrom(this);
445
446
  return a;
@@ -462,7 +463,7 @@ export default class ICalAttendee {
462
463
  * @since 0.2.0
463
464
  */
464
465
  delegatesFrom (options: ICalAttendee | ICalAttendeeData | string): ICalAttendee {
465
- const a = options instanceof ICalAttendee ? options : this.event.createAttendee(options);
466
+ const a = options instanceof ICalAttendee ? options : this.parent.createAttendee(options);
466
467
  this.delegatedFrom(a);
467
468
  a.delegatedTo(this);
468
469
  return a;