ical-generator 10.2.0-develop.2 → 10.2.0-develop.3
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/dist/index.cjs +34 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -1
- package/dist/index.d.ts +76 -1
- package/dist/index.js +32 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/event.ts +175 -0
- package/src/index.ts +3 -0
- package/src/types.ts +32 -0
package/package.json
CHANGED
package/src/event.ts
CHANGED
|
@@ -15,12 +15,14 @@ import {
|
|
|
15
15
|
generateCustomAttributes,
|
|
16
16
|
isRRule,
|
|
17
17
|
toDate,
|
|
18
|
+
toDurationString,
|
|
18
19
|
toJSON,
|
|
19
20
|
} from './tools.ts';
|
|
20
21
|
import {
|
|
21
22
|
type ICalDateTimeValue,
|
|
22
23
|
type ICalDescription,
|
|
23
24
|
ICalEventRepeatingFreq,
|
|
25
|
+
type ICalEventTravelTime,
|
|
24
26
|
type ICalLocation,
|
|
25
27
|
type ICalOrganizer,
|
|
26
28
|
type ICalRepeatingOptions,
|
|
@@ -78,6 +80,7 @@ export interface ICalEventData {
|
|
|
78
80
|
summary?: string;
|
|
79
81
|
timezone?: null | string;
|
|
80
82
|
transparency?: ICalEventTransparency | null;
|
|
83
|
+
travelTime?: ICalEventTravelTime | null;
|
|
81
84
|
url?: null | string;
|
|
82
85
|
x?:
|
|
83
86
|
| [string, string][]
|
|
@@ -110,6 +113,7 @@ export interface ICalEventJSONData {
|
|
|
110
113
|
summary: string;
|
|
111
114
|
timezone: null | string;
|
|
112
115
|
transparency: ICalEventTransparency | null;
|
|
116
|
+
travelTime: ICalEventTravelTime | null;
|
|
113
117
|
url: null | string;
|
|
114
118
|
x: { key: string; value: string }[];
|
|
115
119
|
}
|
|
@@ -153,6 +157,7 @@ interface ICalEventInternalData {
|
|
|
153
157
|
summary: string;
|
|
154
158
|
timezone: null | string;
|
|
155
159
|
transparency: ICalEventTransparency | null;
|
|
160
|
+
travelTime: ICalEventTravelTime | null;
|
|
156
161
|
url: null | string;
|
|
157
162
|
x: [string, string][];
|
|
158
163
|
}
|
|
@@ -203,6 +208,7 @@ export default class ICalEvent {
|
|
|
203
208
|
summary: '',
|
|
204
209
|
timezone: null,
|
|
205
210
|
transparency: null,
|
|
211
|
+
travelTime: null,
|
|
206
212
|
url: null,
|
|
207
213
|
x: [],
|
|
208
214
|
};
|
|
@@ -237,6 +243,7 @@ export default class ICalEvent {
|
|
|
237
243
|
if (data.attachments !== undefined) this.attachments(data.attachments);
|
|
238
244
|
if (data.transparency !== undefined)
|
|
239
245
|
this.transparency(data.transparency);
|
|
246
|
+
if (data.travelTime !== undefined) this.travelTime(data.travelTime);
|
|
240
247
|
if (data.created !== undefined) this.created(data.created);
|
|
241
248
|
if (data.lastModified !== undefined)
|
|
242
249
|
this.lastModified(data.lastModified);
|
|
@@ -1781,6 +1788,99 @@ export default class ICalEvent {
|
|
|
1781
1788
|
'\r\n';
|
|
1782
1789
|
}
|
|
1783
1790
|
|
|
1791
|
+
// Travel time
|
|
1792
|
+
if (this.data.travelTime) {
|
|
1793
|
+
g +=
|
|
1794
|
+
'X-APPLE-TRAVEL-DURATION;VALUE=DURATION:' +
|
|
1795
|
+
toDurationString(this.data.travelTime.seconds) +
|
|
1796
|
+
'\r\n';
|
|
1797
|
+
|
|
1798
|
+
if (this.data.location) {
|
|
1799
|
+
if (this.data.travelTime.suggestionBehavior) {
|
|
1800
|
+
g +=
|
|
1801
|
+
'X-APPLE-TRAVEL-ADVISORY-BEHAVIOR:' +
|
|
1802
|
+
this.data.travelTime.suggestionBehavior +
|
|
1803
|
+
'\r\n';
|
|
1804
|
+
}
|
|
1805
|
+
if (this.data.travelTime.startFrom) {
|
|
1806
|
+
g += 'X-APPLE-TRAVEL-START;';
|
|
1807
|
+
|
|
1808
|
+
const travelStartParameters: string[] = [];
|
|
1809
|
+
|
|
1810
|
+
travelStartParameters.push(
|
|
1811
|
+
'ROUTING=' +
|
|
1812
|
+
this.data.travelTime.startFrom.transportation,
|
|
1813
|
+
);
|
|
1814
|
+
travelStartParameters.push('VALUE=URI');
|
|
1815
|
+
|
|
1816
|
+
if (
|
|
1817
|
+
'address' in this.data.travelTime.startFrom.location &&
|
|
1818
|
+
this.data.travelTime.startFrom.location.address
|
|
1819
|
+
) {
|
|
1820
|
+
travelStartParameters.push(
|
|
1821
|
+
'X-ADDRESS=' +
|
|
1822
|
+
escape(
|
|
1823
|
+
this.data.travelTime.startFrom.location
|
|
1824
|
+
.address,
|
|
1825
|
+
false,
|
|
1826
|
+
),
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
if (
|
|
1831
|
+
'radius' in this.data.travelTime.startFrom.location &&
|
|
1832
|
+
this.data.travelTime.startFrom.location.radius
|
|
1833
|
+
) {
|
|
1834
|
+
travelStartParameters.push(
|
|
1835
|
+
'X-APPLE-RADIUS=' +
|
|
1836
|
+
escape(
|
|
1837
|
+
this.data.travelTime.startFrom.location
|
|
1838
|
+
.radius,
|
|
1839
|
+
false,
|
|
1840
|
+
),
|
|
1841
|
+
);
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
if (
|
|
1845
|
+
'title' in this.data.travelTime.startFrom.location &&
|
|
1846
|
+
this.data.travelTime.startFrom.location.title
|
|
1847
|
+
) {
|
|
1848
|
+
travelStartParameters.push(
|
|
1849
|
+
'X-TITLE=' +
|
|
1850
|
+
escape(
|
|
1851
|
+
this.data.travelTime.startFrom.location
|
|
1852
|
+
.title,
|
|
1853
|
+
false,
|
|
1854
|
+
),
|
|
1855
|
+
);
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
g += travelStartParameters.join(';');
|
|
1859
|
+
|
|
1860
|
+
if (
|
|
1861
|
+
'geo' in this.data.travelTime.startFrom.location &&
|
|
1862
|
+
this.data.travelTime.startFrom.location.geo
|
|
1863
|
+
) {
|
|
1864
|
+
g +=
|
|
1865
|
+
':geo:' +
|
|
1866
|
+
escape(
|
|
1867
|
+
this.data.travelTime.startFrom.location.geo
|
|
1868
|
+
?.lat,
|
|
1869
|
+
false,
|
|
1870
|
+
) +
|
|
1871
|
+
',' +
|
|
1872
|
+
escape(
|
|
1873
|
+
this.data.travelTime.startFrom.location.geo
|
|
1874
|
+
?.lon,
|
|
1875
|
+
false,
|
|
1876
|
+
);
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
g += '\r\n';
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1784
1884
|
// DESCRIPTION
|
|
1785
1885
|
if (this.data.description) {
|
|
1786
1886
|
g +=
|
|
@@ -1942,6 +2042,81 @@ export default class ICalEvent {
|
|
|
1942
2042
|
return this;
|
|
1943
2043
|
}
|
|
1944
2044
|
|
|
2045
|
+
/**
|
|
2046
|
+
* Get the event's travel time
|
|
2047
|
+
* @returns {null|ICalEventTravelTime}
|
|
2048
|
+
*/
|
|
2049
|
+
travelTime(): ICalEventTravelTime | null;
|
|
2050
|
+
/**
|
|
2051
|
+
* Use this method to set the event's travel time. \
|
|
2052
|
+
* (Only supported on Apple calendar clients)
|
|
2053
|
+
*
|
|
2054
|
+
* ```typescript
|
|
2055
|
+
* // Set fixed travel time in seconds, doesn't recalculate if traffic conditions change
|
|
2056
|
+
* event.travelTime(60 * 30) // 30 minutes travel time
|
|
2057
|
+
* ```
|
|
2058
|
+
*
|
|
2059
|
+
* @param {null|number} travelTime Travel time in seconds
|
|
2060
|
+
*/
|
|
2061
|
+
travelTime(travelTime: null | number): this;
|
|
2062
|
+
/**
|
|
2063
|
+
* Use this method to set the event's travel time. \
|
|
2064
|
+
* (Only supported on Apple calendar clients)
|
|
2065
|
+
*
|
|
2066
|
+
* NOTE: suggestionBehavior and travelStart will only be set if the event has a location
|
|
2067
|
+
*
|
|
2068
|
+
* ```typescript
|
|
2069
|
+
* // Set travel time in seconds, if startFrom is present it adapts if traffic conditions change
|
|
2070
|
+
* event.travelTime({
|
|
2071
|
+
* seconds: 60 * 30, // 30 minutes travel time
|
|
2072
|
+
* suggestionBehavior: ICalEventTravelTimeSuggestion.AUTOMATIC, // Let Apple Calendar client decide how to handle suggestions
|
|
2073
|
+
* startFrom: {
|
|
2074
|
+
* location: {
|
|
2075
|
+
* geo: {
|
|
2076
|
+
* lat: 50.000000,
|
|
2077
|
+
* lon: 10.000000
|
|
2078
|
+
* },
|
|
2079
|
+
* title: "Private address"
|
|
2080
|
+
* },
|
|
2081
|
+
* transportation: ICalEventTravelTimeTransportation.BICYCLE // Use bicycle routes for travel time recalculation
|
|
2082
|
+
* }
|
|
2083
|
+
* })
|
|
2084
|
+
* ```
|
|
2085
|
+
*
|
|
2086
|
+
* @param {null|ICalEventTravelTime} travelTime Travel time object
|
|
2087
|
+
*/
|
|
2088
|
+
travelTime(travelTime: ICalEventTravelTime | null): this;
|
|
2089
|
+
travelTime(
|
|
2090
|
+
travelTime?: ICalEventTravelTime | null | number,
|
|
2091
|
+
): ICalEventTravelTime | null | number | this {
|
|
2092
|
+
if (travelTime === undefined) {
|
|
2093
|
+
return this.data.travelTime;
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
if (typeof travelTime === 'number' && travelTime <= 0) {
|
|
2097
|
+
throw new Error('`travelTime` has to be more than 0!');
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
if (
|
|
2101
|
+
travelTime &&
|
|
2102
|
+
typeof travelTime === 'object' &&
|
|
2103
|
+
'seconds' in travelTime &&
|
|
2104
|
+
travelTime.seconds <= 0
|
|
2105
|
+
) {
|
|
2106
|
+
throw new Error('`travelTime.seconds` has to be more than 0!');
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
if (typeof travelTime === 'number') {
|
|
2110
|
+
this.data.travelTime = {
|
|
2111
|
+
seconds: travelTime,
|
|
2112
|
+
};
|
|
2113
|
+
return this;
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
this.data.travelTime = travelTime;
|
|
2117
|
+
return this;
|
|
2118
|
+
}
|
|
2119
|
+
|
|
1945
2120
|
/**
|
|
1946
2121
|
* Get the event's ID
|
|
1947
2122
|
* @since 0.2.0
|
package/src/index.ts
CHANGED
|
@@ -102,6 +102,9 @@ export {
|
|
|
102
102
|
type ICalDayJsStub,
|
|
103
103
|
type ICalDescription,
|
|
104
104
|
ICalEventRepeatingFreq,
|
|
105
|
+
type ICalEventTravelTime,
|
|
106
|
+
ICalEventTravelTimeSuggestion,
|
|
107
|
+
ICalEventTravelTimeTransportation,
|
|
105
108
|
type ICalGeo,
|
|
106
109
|
type ICalLocation,
|
|
107
110
|
type ICalLocationWithoutTitle,
|
package/src/types.ts
CHANGED
|
@@ -8,6 +8,29 @@ export enum ICalEventRepeatingFreq {
|
|
|
8
8
|
YEARLY = 'YEARLY',
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Used in ICalEvent.travelTime()
|
|
13
|
+
*
|
|
14
|
+
* Controls whether Apple clients give suggestions like "Time to leave" notifications, route prompts in Apple Maps, etc.
|
|
15
|
+
*/
|
|
16
|
+
export enum ICalEventTravelTimeSuggestion {
|
|
17
|
+
AUTOMATIC = 'AUTOMATIC',
|
|
18
|
+
DISABLED = 'DISABLED',
|
|
19
|
+
ENABLED = 'ENABLED',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Used in ICalEvent.travelTime()
|
|
24
|
+
*
|
|
25
|
+
* Controls which mode of transportation is used by Apple Calendar clients for calculating travel time and suggesting routes
|
|
26
|
+
*/
|
|
27
|
+
export enum ICalEventTravelTimeTransportation {
|
|
28
|
+
BICYCLE = 'BICYCLE',
|
|
29
|
+
CAR = 'CAR',
|
|
30
|
+
TRANSIT = 'TRANSIT',
|
|
31
|
+
WALKING = 'WALKING',
|
|
32
|
+
}
|
|
33
|
+
|
|
11
34
|
export enum ICalWeekday {
|
|
12
35
|
FR = 'FR',
|
|
13
36
|
MO = 'MO',
|
|
@@ -50,6 +73,15 @@ export interface ICalDescription {
|
|
|
50
73
|
plain: string;
|
|
51
74
|
}
|
|
52
75
|
|
|
76
|
+
export interface ICalEventTravelTime {
|
|
77
|
+
seconds: number;
|
|
78
|
+
startFrom?: {
|
|
79
|
+
location: ICalLocation;
|
|
80
|
+
transportation: ICalEventTravelTimeTransportation;
|
|
81
|
+
};
|
|
82
|
+
suggestionBehavior?: ICalEventTravelTimeSuggestion;
|
|
83
|
+
}
|
|
84
|
+
|
|
53
85
|
export interface ICalGeo {
|
|
54
86
|
lat: number;
|
|
55
87
|
lon: number;
|