From 10b80144ae5c17e1b33e7bd750b29e7997294f93 Mon Sep 17 00:00:00 2001 From: Leonardo Dominguez Date: Mon, 21 Oct 2019 15:05:55 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=99=8C=20implement=20apple=20event=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.d.ts | 10 ++++++++++ src/event.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/index.d.ts b/index.d.ts index 35f1f1f08..ab5a39a82 100644 --- a/index.d.ts +++ b/index.d.ts @@ -65,6 +65,7 @@ declare module 'ical-generator' { lastModified?: moment.Moment | Date; description?: string; location?: string; + appleLocation: AppleLocationData; geo?: GeoData; url?: string; sequence?: number; @@ -137,6 +138,13 @@ declare module 'ical-generator' { lon: number; } + interface AppleLocationData { + title: string; + address: string; + radius: number; + geo: GeoData; + } + /** * The calendar object containing all event data */ @@ -203,6 +211,8 @@ declare module 'ical-generator' { summary(summary: string): ICalEvent; location(): string; location(location: string): ICalEvent; + appleLocation(): AppleLocationData; + appleLocation(location: AppleLocationData): ICalEvent; geo(): string | null; geo(geo: string | GeoData | null): ICalEvent; description(): string; diff --git a/src/event.js b/src/event.js index 914fda8f5..403eaed8a 100755 --- a/src/event.js +++ b/src/event.js @@ -26,6 +26,7 @@ class ICalEvent { repeating: null, summary: '', location: null, + appleLocation: null, geo: null, description: null, htmlDescription: null, @@ -53,6 +54,7 @@ class ICalEvent { 'repeating', 'summary', 'location', + 'appleLocation', 'geo', 'description', 'htmlDescription', @@ -548,6 +550,27 @@ class ICalEvent { return this; } + /** + * Set/Get the Apple event's location + * + * @param {object} [location] + * @since 0.2.0 + * @returns {ICalEvent|String} + */ + appleLocation (appleLocation) { + if (appleLocation === undefined) { + return this._data.appleLocation; + } + + if (!appleLocation.title || !appleLocation.address || !appleLocation.radius || !appleLocation.geo || !appleLocation.geo.lat || !appleLocation.geo.lon) { + throw new Error('`appleLocation` isn\'t formatted correctly.'); + } + + this._data.appleLocation = appleLocation; + this._data.location = null; + return this; + } + /** * Set/Get the event's geo * @@ -1063,6 +1086,12 @@ class ICalEvent { g += 'LOCATION:' + ICalTools.escape(this._data.location) + '\r\n'; } + // APPLE LOCATION + if (this._data.appleLocation) { + g += 'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-ADDRESS=' + ICalTools.escape(this._data.appleLocation.address) + ';X-APPLE-RADIUS=' + ICalTools.escape(this._data.appleLocation.radius) + ';X-TITLE=' + ICalTools.escape(this._data.appleLocation.title) + + '\r\n:geo:' + ICalTools.escape(this._data.appleLocation.geo.lat) + ',' + ICalTools.escape(this._data.appleLocation.geo.lon) + '\r\n'; + } + // GEO if (this._data.geo) { g += 'GEO:' + ICalTools.escape(this._data.geo.lat) + ';' + ICalTools.escape(this._data.geo.lon) + '\r\n';