Skip to content

Commit

Permalink
Merge branch 'apple-event-feature' of https://github.com/focux/ical-g…
Browse files Browse the repository at this point in the history
…enerator into feature/apple-calendar
  • Loading branch information
sebbo2002 committed Apr 13, 2020
2 parents 8e5f3b6 + 6e351b3 commit aa840b8
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 @@ -54,6 +55,7 @@ class ICalEvent {
'repeating',
'summary',
'location',
'appleLocation',
'geo',
'description',
'htmlDescription',
Expand Down Expand Up @@ -550,6 +552,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 = this._data.appleLocation.title + '\n' + this._data.appleLocation.address;
return this;
}

/**
* Set/Get the event's geo
*
Expand Down Expand Up @@ -1080,6 +1103,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) +
':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 aa840b8

Please sign in to comment.