ical-generator 6.0.2-develop.9 → 7.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/package.json CHANGED
@@ -125,5 +125,5 @@
125
125
  "test": "mocha"
126
126
  },
127
127
  "type": "module",
128
- "version": "6.0.2-develop.9"
128
+ "version": "7.0.0-develop.2"
129
129
  }
package/src/event.ts CHANGED
@@ -360,16 +360,11 @@ export default class ICalEvent {
360
360
  start(start: ICalDateTimeValue): this;
361
361
  start(start?: ICalDateTimeValue): this | ICalDateTimeValue {
362
362
  if (start === undefined) {
363
+ this.swapStartAndEndIfRequired();
363
364
  return this.data.start;
364
365
  }
365
366
 
366
367
  this.data.start = checkDate(start, 'start');
367
- if (this.data.start && this.data.end && toDate(this.data.start).getTime() > toDate(this.data.end).getTime()) {
368
- const t = this.data.start;
369
- this.data.start = this.data.end;
370
- this.data.end = t;
371
- }
372
-
373
368
  return this;
374
369
  }
375
370
 
@@ -391,6 +386,7 @@ export default class ICalEvent {
391
386
  end(end: ICalDateTimeValue | null): this;
392
387
  end(end?: ICalDateTimeValue | null): this | ICalDateTimeValue | null {
393
388
  if (end === undefined) {
389
+ this.swapStartAndEndIfRequired();
394
390
  return this.data.end;
395
391
  }
396
392
  if (end === null) {
@@ -399,13 +395,19 @@ export default class ICalEvent {
399
395
  }
400
396
 
401
397
  this.data.end = checkDate(end, 'end');
398
+ return this;
399
+ }
400
+
401
+ /**
402
+ * Checks if the start date is after the end date and swaps them if necessary.
403
+ * @private
404
+ */
405
+ private swapStartAndEndIfRequired(): void {
402
406
  if (this.data.start && this.data.end && toDate(this.data.start).getTime() > toDate(this.data.end).getTime()) {
403
407
  const t = this.data.start;
404
408
  this.data.start = this.data.end;
405
409
  this.data.end = t;
406
410
  }
407
-
408
- return this;
409
411
  }
410
412
 
411
413
  /**
@@ -880,7 +882,7 @@ export default class ICalEvent {
880
882
 
881
883
  /**
882
884
  * Set the event's location by passing a string (minimum) or
883
- * an {@link ICalLocation} object which will also fill the iCal
885
+ * an {@link ICalLocationWithTitle} object which will also fill the iCal
884
886
  * `GEO` attribute and Apple's `X-APPLE-STRUCTURED-LOCATION`.
885
887
  *
886
888
  * ```javascript
@@ -904,6 +906,22 @@ export default class ICalEvent {
904
906
  * GEO:52.50363;13.32865
905
907
  * ```
906
908
  *
909
+ * Since v6.1.0 you can also pass a {@link ICalLocationWithoutTitle} object to pass
910
+ * the geolocation only. This will only fill the iCal `GEO` attribute.
911
+ *
912
+ * ```javascript
913
+ * event.location({
914
+ * geo: {
915
+ * lat: 52.503630,
916
+ * lon: 13.328650
917
+ * }
918
+ * });
919
+ * ```
920
+ *
921
+ * ```text
922
+ * GEO:52.50363;13.32865
923
+ * ```
924
+ *
907
925
  * @since 0.2.0
908
926
  */
909
927
  location(location: ICalLocation | string | null): this;
@@ -917,10 +935,11 @@ export default class ICalEvent {
917
935
  };
918
936
  return this;
919
937
  }
920
- if (
921
- (location && !location.title) ||
922
- (location?.geo && (!isFinite(location.geo.lat) || !isFinite(location.geo.lon)))
923
- ) {
938
+ if (location && (
939
+ ('title' in location && !location.title) ||
940
+ (location?.geo && (!isFinite(location.geo.lat) || !isFinite(location.geo.lon))) ||
941
+ (!('title' in location) && !location?.geo)
942
+ )) {
924
943
  throw new Error(
925
944
  '`location` isn\'t formatted correctly. See https://sebbo2002.github.io/ical-generator/'+
926
945
  'develop/reference/classes/ICalEvent.html#location'
@@ -1612,6 +1631,7 @@ export default class ICalEvent {
1612
1631
  });
1613
1632
  }
1614
1633
 
1634
+ this.swapStartAndEndIfRequired();
1615
1635
  return Object.assign({}, this.data, {
1616
1636
  start: toJSON(this.data.start) || null,
1617
1637
  end: toJSON(this.data.end) || null,
@@ -1643,6 +1663,7 @@ export default class ICalEvent {
1643
1663
  // SEQUENCE
1644
1664
  g += 'SEQUENCE:' + this.data.sequence + '\r\n';
1645
1665
 
1666
+ this.swapStartAndEndIfRequired();
1646
1667
  g += 'DTSTAMP:' + formatDate(this.calendar.timezone(), this.data.stamp) + '\r\n';
1647
1668
  if (this.data.allDay) {
1648
1669
  g += 'DTSTART;VALUE=DATE:' + formatDate(this.calendar.timezone(), this.data.start, true) + '\r\n';
@@ -1751,7 +1772,7 @@ export default class ICalEvent {
1751
1772
  }
1752
1773
 
1753
1774
  // LOCATION
1754
- if (this.data.location?.title) {
1775
+ if (this.data.location && 'title' in this.data.location && this.data.location.title) {
1755
1776
  g += 'LOCATION:' + escape(
1756
1777
  this.data.location.title +
1757
1778
  (this.data.location.address ? '\n' + this.data.location.address : ''),
@@ -1766,13 +1787,14 @@ export default class ICalEvent {
1766
1787
  ':geo:' + escape(this.data.location.geo?.lat, false) + ',' +
1767
1788
  escape(this.data.location.geo?.lon, false) + '\r\n';
1768
1789
  }
1769
-
1770
- if (this.data.location.geo) {
1771
- g += 'GEO:' + escape(this.data.location.geo?.lat, false) + ';' +
1772
- escape(this.data.location.geo?.lon, false) + '\r\n';
1773
- }
1774
1790
  }
1775
1791
 
1792
+ // GEO
1793
+ if (this.data.location && 'geo' in this.data.location && this.data.location.geo) {
1794
+ g += 'GEO:' + escape(this.data.location.geo?.lat, false) + ';' +
1795
+ escape(this.data.location.geo?.lon, false) + '\r\n';
1796
+ }
1797
+
1776
1798
  // DESCRIPTION
1777
1799
  if (this.data.description) {
1778
1800
  g += 'DESCRIPTION:' + escape(this.data.description.plain, false) + '\r\n';
package/src/index.ts CHANGED
@@ -99,6 +99,8 @@ export {
99
99
  ICalDateTimeValue,
100
100
  ICalRepeatingOptions,
101
101
  ICalLocation,
102
+ ICalLocationWithTitle,
103
+ ICalLocationWithoutTitle,
102
104
  ICalGeo,
103
105
  ICalOrganizer,
104
106
  ICalDescription,
package/src/types.ts CHANGED
@@ -19,13 +19,19 @@ export interface ICalRepeatingOptions {
19
19
  startOfWeek?: ICalWeekday;
20
20
  }
21
21
 
22
- export interface ICalLocation {
22
+ export type ICalLocation = ICalLocationWithTitle | ICalLocationWithoutTitle;
23
+
24
+ export interface ICalLocationWithTitle {
23
25
  title: string;
24
26
  address?: string;
25
27
  radius?: number;
26
28
  geo?: ICalGeo;
27
29
  }
28
30
 
31
+ export interface ICalLocationWithoutTitle {
32
+ geo: ICalGeo;
33
+ }
34
+
29
35
  export interface ICalGeo {
30
36
  lat: number;
31
37
  lon: number;