ical-generator 4.0.0 → 4.1.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/package.json CHANGED
@@ -9,19 +9,19 @@
9
9
  "description": "ical-generator is a small piece of code which generates ical calendar files",
10
10
  "devDependencies": {
11
11
  "@qiwi/semantic-release-gh-pages-plugin": "^5.2.5",
12
- "@semantic-release/changelog": "^6.0.2",
12
+ "@semantic-release/changelog": "^6.0.3",
13
13
  "@semantic-release/exec": "^6.0.3",
14
14
  "@semantic-release/git": "^10.0.1",
15
- "@semantic-release/npm": "^9.0.2",
15
+ "@semantic-release/npm": "^10.0.3",
16
16
  "@touch4it/ical-timezones": "^1.9.0",
17
- "@types/luxon": "^3.2.0",
17
+ "@types/luxon": "^3.3.0",
18
18
  "@types/mocha": "^10.0.1",
19
- "@types/node": "^18.15.3",
20
- "@typescript-eslint/eslint-plugin": "^5.54.1",
21
- "@typescript-eslint/parser": "^5.54.1",
19
+ "@types/node": "^18.15.11",
20
+ "@typescript-eslint/eslint-plugin": "^5.57.0",
21
+ "@typescript-eslint/parser": "^5.57.0",
22
22
  "c8": "^7.11.3",
23
23
  "dayjs": "^1.11.7",
24
- "eslint": "^8.36.0",
24
+ "eslint": "^8.37.0",
25
25
  "eslint-plugin-jsonc": "^2.7.0",
26
26
  "esm": "^3.2.25",
27
27
  "license-checker": "^25.0.1",
@@ -29,17 +29,17 @@
29
29
  "mocha": "^10.2.0",
30
30
  "mochawesome": "^7.1.3",
31
31
  "moment": "^2.29.4",
32
- "moment-timezone": "^0.5.41",
32
+ "moment-timezone": "^0.5.43",
33
33
  "nyc": "^15.1.0",
34
34
  "portfinder": "^1.0.32",
35
35
  "rrule": "^2.7.2",
36
- "semantic-release": "^20.1.3",
36
+ "semantic-release": "^21.0.1",
37
37
  "semantic-release-license": "^1.0.2",
38
38
  "source-map-support": "^0.5.21",
39
39
  "ts-node": "^10.9.1",
40
40
  "tsup": "^6.7.0",
41
41
  "typedoc": "^0.23.28",
42
- "typescript": "^5.0.2"
42
+ "typescript": "^5.0.4"
43
43
  },
44
44
  "engines": {
45
45
  "node": "^14.8.0 || >=16.0.0"
@@ -128,5 +128,5 @@
128
128
  "test": "mocha"
129
129
  },
130
130
  "type": "module",
131
- "version": "4.0.0"
131
+ "version": "4.1.0-develop.2"
132
132
  }
package/src/alarm.ts CHANGED
@@ -18,6 +18,13 @@ export enum ICalAlarmType {
18
18
  audio = 'audio'
19
19
  }
20
20
 
21
+ export const ICalAlarmRelatesTo = {
22
+ end: 'END',
23
+ start: 'START'
24
+ } as const;
25
+
26
+ export type ICalAlarmRelatesTo = typeof ICalAlarmRelatesTo[keyof typeof ICalAlarmRelatesTo];
27
+
21
28
  export type ICalAlarmTypeValue = keyof ICalAlarmType;
22
29
 
23
30
  export interface ICalAttachment {
@@ -28,6 +35,7 @@ export interface ICalAttachment {
28
35
  export interface ICalAlarmData {
29
36
  type?: ICalAlarmType | null;
30
37
  trigger?: number | ICalDateTimeValue | null;
38
+ relatesTo?: ICalAlarmRelatesTo | null;
31
39
  triggerBefore?: number | ICalDateTimeValue | null;
32
40
  triggerAfter?: number | ICalDateTimeValue | null;
33
41
  repeat?: number | null;
@@ -40,6 +48,7 @@ export interface ICalAlarmData {
40
48
  interface ICalInternalAlarmData {
41
49
  type: ICalAlarmType | null;
42
50
  trigger: ICalDateTimeValue | number | null;
51
+ relatesTo: ICalAlarmRelatesTo | null;
43
52
  repeat: number | null;
44
53
  interval: number | null;
45
54
  attach: ICalAttachment | null;
@@ -50,6 +59,7 @@ interface ICalInternalAlarmData {
50
59
  export interface ICalAlarmJSONData {
51
60
  type: ICalAlarmType | null;
52
61
  trigger: string | number | null;
62
+ relatesTo: ICalAlarmRelatesTo | null;
53
63
  repeat: number | null;
54
64
  interval: number | null;
55
65
  attach: ICalAttachment | null;
@@ -91,6 +101,7 @@ export default class ICalAlarm {
91
101
  this.data = {
92
102
  type: null,
93
103
  trigger: null,
104
+ relatesTo: null,
94
105
  repeat: null,
95
106
  interval: null,
96
107
  attach: null,
@@ -205,6 +216,55 @@ export default class ICalAlarm {
205
216
  return this;
206
217
  }
207
218
 
219
+ /**
220
+ * Get to which time alarm trigger relates to.
221
+ * Can be either `START` or `END`. If the value is
222
+ * `START` the alarm is triggerd relative to the event start time.
223
+ * If the value is `END` the alarm is triggerd relative to the event end time
224
+ *
225
+ * @since 4.0.1
226
+ */
227
+ relatesTo(): ICalAlarmRelatesTo | null;
228
+
229
+ /**
230
+ * Use this method to set to which time alarm trigger relates to.
231
+ * Works only if trigger is a `number`
232
+ *
233
+ * ```javascript
234
+ * const cal = ical();
235
+ * const event = cal.createEvent();
236
+ * const alarm = cal.createAlarm();
237
+ *
238
+ * alarm.trigger(600); // -> 10 minutes before event starts
239
+ *
240
+ * alarm.relatesTo('START'); // -> 10 minutes before event starts
241
+ * alarm.relatesTo('END'); // -> 10 minutes before event ends
242
+ *
243
+ * alarm.trigger(-600); // -> 10 minutes after event starts
244
+ *
245
+ * alarm.relatesTo('START'); // -> 10 minutes after event starts
246
+ * alarm.relatesTo('END'); // -> 10 minutes after event ends
247
+ * ```
248
+ * @since 4.0.1
249
+ */
250
+ relatesTo(relatesTo: ICalAlarmRelatesTo | null): this;
251
+ relatesTo(relatesTo?: ICalAlarmRelatesTo | null): this | ICalAlarmRelatesTo | null {
252
+ if (relatesTo === undefined) {
253
+ return this.data.relatesTo;
254
+ }
255
+ if (!relatesTo) {
256
+ this.data.relatesTo = null;
257
+ return this;
258
+ }
259
+
260
+ if (!Object.values(ICalAlarmRelatesTo).includes(relatesTo)) {
261
+ throw new Error('`relatesTo` is not correct, must be either `START` or `END`!');
262
+ }
263
+
264
+ this.data.relatesTo = relatesTo;
265
+ return this;
266
+ }
267
+
208
268
 
209
269
  /**
210
270
  * Get the trigger time for the alarm. Can either
@@ -569,11 +629,16 @@ export default class ICalAlarm {
569
629
  // ACTION
570
630
  g += 'ACTION:' + this.data.type.toUpperCase() + '\r\n';
571
631
 
572
- if (typeof this.data.trigger === 'number' && this.data.trigger > 0) {
573
- g += 'TRIGGER;RELATED=END:' + toDurationString(this.data.trigger) + '\r\n';
574
- }
632
+ if (typeof this.data.trigger === 'number' && this.data.relatesTo === null) {
633
+ if (this.data.trigger > 0) {
634
+ g += 'TRIGGER;RELATED=END:' + toDurationString(this.data.trigger) + '\r\n';
635
+ }
636
+ else {
637
+ g += 'TRIGGER:' + toDurationString(this.data.trigger) + '\r\n';
638
+ }
639
+ }
575
640
  else if (typeof this.data.trigger === 'number') {
576
- g += 'TRIGGER:' + toDurationString(this.data.trigger) + '\r\n';
641
+ g += 'TRIGGER;RELATED=' + this.data.relatesTo.toUpperCase() + ':' + toDurationString(this.data.trigger) + '\r\n';
577
642
  }
578
643
  else {
579
644
  g += 'TRIGGER;VALUE=DATE-TIME:' + formatDate(this.event.timezone(), this.data.trigger) + '\r\n';
package/src/event.ts CHANGED
@@ -1086,7 +1086,7 @@ export default class ICalEvent {
1086
1086
  *
1087
1087
  * ```javascript
1088
1088
  * import ical, {ICalEventBusyStatus} from 'ical-generator';
1089
- * event.busystatus(ICalEventStatus.BUSY);
1089
+ * event.busystatus(ICalEventBusyStatus.BUSY);
1090
1090
  * ```
1091
1091
  *
1092
1092
  * @since 1.0.2