Skip to content

Commit

Permalink
🙌 implement apple event tag
Browse files Browse the repository at this point in the history
  • Loading branch information
focux committed Oct 21, 2019
1 parent f64e06b commit 10b8014
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ declare module 'ical-generator' {
lastModified?: moment.Moment | Date;
description?: string;
location?: string;
appleLocation: AppleLocationData;
geo?: GeoData;
url?: string;
sequence?: number;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ICalEvent {
repeating: null,
summary: '',
location: null,
appleLocation: null,
geo: null,
description: null,
htmlDescription: null,
Expand Down Expand Up @@ -53,6 +54,7 @@ class ICalEvent {
'repeating',
'summary',
'location',
'appleLocation',
'geo',
'description',
'htmlDescription',
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 10b8014

Please sign in to comment.