ical-generator 10.1.0 → 10.2.0-develop.1
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 +24 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +21 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/calendar.ts +34 -0
- package/src/tools.ts +5 -5
package/package.json
CHANGED
package/src/calendar.ts
CHANGED
|
@@ -26,6 +26,7 @@ export enum ICalCalendarMethod {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export interface ICalCalendarData {
|
|
29
|
+
color?: null | string;
|
|
29
30
|
description?: null | string;
|
|
30
31
|
events?: (ICalEvent | ICalEventData)[];
|
|
31
32
|
method?: ICalCalendarMethod | null;
|
|
@@ -43,6 +44,7 @@ export interface ICalCalendarData {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export interface ICalCalendarJSONData {
|
|
47
|
+
color: null | string;
|
|
46
48
|
description: null | string;
|
|
47
49
|
events: ICalEventJSONData[];
|
|
48
50
|
method: ICalCalendarMethod | null;
|
|
@@ -63,6 +65,7 @@ export interface ICalCalendarProdIdData {
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
interface ICalCalendarInternalData {
|
|
68
|
+
color: null | string;
|
|
66
69
|
description: null | string;
|
|
67
70
|
events: ICalEvent[];
|
|
68
71
|
method: ICalCalendarMethod | null;
|
|
@@ -128,6 +131,7 @@ export default class ICalCalendar {
|
|
|
128
131
|
*/
|
|
129
132
|
constructor(data: ICalCalendarData = {}) {
|
|
130
133
|
this.data = {
|
|
134
|
+
color: null,
|
|
131
135
|
description: null,
|
|
132
136
|
events: [],
|
|
133
137
|
method: null,
|
|
@@ -150,6 +154,7 @@ export default class ICalCalendar {
|
|
|
150
154
|
if (data.url !== undefined) this.url(data.url);
|
|
151
155
|
if (data.scale !== undefined) this.scale(data.scale);
|
|
152
156
|
if (data.ttl !== undefined) this.ttl(data.ttl);
|
|
157
|
+
if (data.color !== undefined) this.color(data.color);
|
|
153
158
|
if (data.events !== undefined) this.events(data.events);
|
|
154
159
|
if (data.x !== undefined) this.x(data.x);
|
|
155
160
|
}
|
|
@@ -165,6 +170,30 @@ export default class ICalCalendar {
|
|
|
165
170
|
return this;
|
|
166
171
|
}
|
|
167
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Get your feed's color
|
|
175
|
+
* @returns {null|string}
|
|
176
|
+
*/
|
|
177
|
+
color(): null | string;
|
|
178
|
+
/**
|
|
179
|
+
* Set your feed's color
|
|
180
|
+
* (Only supported on Apple calendar clients)
|
|
181
|
+
* @param {null|string} color \# followed by six character hex color code
|
|
182
|
+
*/
|
|
183
|
+
color(color: null | string): this;
|
|
184
|
+
color(color?: null | string): null | string | this {
|
|
185
|
+
if (color === undefined) {
|
|
186
|
+
return this.data.color;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Only six character hex color codes seem to be supported
|
|
190
|
+
if (typeof color === 'string' && !/^#[A-F0-9]{6}$/gi.test(color)) {
|
|
191
|
+
throw new Error('`color` is malformed!');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this.data.color = color ? String(color).toUpperCase() : null;
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
168
197
|
/**
|
|
169
198
|
* Creates a new {@link ICalEvent} and returns it. Use options to prefill the event's attributes.
|
|
170
199
|
* Calling this method without options will create an empty event.
|
|
@@ -642,6 +671,11 @@ export default class ICalCalendar {
|
|
|
642
671
|
g += 'X-PUBLISHED-TTL:' + toDurationString(this.data.ttl) + '\r\n';
|
|
643
672
|
}
|
|
644
673
|
|
|
674
|
+
// Apple calendar color
|
|
675
|
+
if (this.data.color) {
|
|
676
|
+
g += 'X-APPLE-CALENDAR-COLOR:' + this.data.color + '\r\n';
|
|
677
|
+
}
|
|
678
|
+
|
|
645
679
|
// Events
|
|
646
680
|
this.data.events.forEach((event) => (g += event.toString()));
|
|
647
681
|
|
package/src/tools.ts
CHANGED
|
@@ -268,14 +268,14 @@ export function formatDate(
|
|
|
268
268
|
|
|
269
269
|
// (!dateonly && !floating) || !timezone => utc
|
|
270
270
|
let s =
|
|
271
|
-
m.getUTCFullYear() +
|
|
271
|
+
m.getUTCFullYear().toString().padStart(4, '0') +
|
|
272
272
|
String(m.getUTCMonth() + 1).padStart(2, '0') +
|
|
273
273
|
m.getUTCDate().toString().padStart(2, '0');
|
|
274
274
|
|
|
275
275
|
// (dateonly || floating) && timezone => tz
|
|
276
276
|
if (timezone) {
|
|
277
277
|
s =
|
|
278
|
-
m.getFullYear() +
|
|
278
|
+
m.getFullYear().toString().padStart(2, '0') +
|
|
279
279
|
String(m.getMonth() + 1).padStart(2, '0') +
|
|
280
280
|
m.getDate().toString().padStart(2, '0');
|
|
281
281
|
}
|
|
@@ -355,7 +355,7 @@ export function formatDate(
|
|
|
355
355
|
// Temporal.PlainDateTime - floating time or convert to timezone
|
|
356
356
|
if (dateonly) {
|
|
357
357
|
return (
|
|
358
|
-
d.year +
|
|
358
|
+
d.year.toString().padStart(4, '0') +
|
|
359
359
|
d.month.toString().padStart(2, '0') +
|
|
360
360
|
d.day.toString().padStart(2, '0')
|
|
361
361
|
);
|
|
@@ -369,7 +369,7 @@ export function formatDate(
|
|
|
369
369
|
|
|
370
370
|
// Floating time - no timezone, no Z
|
|
371
371
|
return (
|
|
372
|
-
d.year +
|
|
372
|
+
d.year.toString().padStart(4, '0') +
|
|
373
373
|
d.month.toString().padStart(2, '0') +
|
|
374
374
|
d.day.toString().padStart(2, '0') +
|
|
375
375
|
'T' +
|
|
@@ -381,7 +381,7 @@ export function formatDate(
|
|
|
381
381
|
} else if (isTemporalPlainDate(d)) {
|
|
382
382
|
// Temporal.PlainDate - date only
|
|
383
383
|
return (
|
|
384
|
-
d.year +
|
|
384
|
+
d.year.toString().padStart(4, '0') +
|
|
385
385
|
d.month.toString().padStart(2, '0') +
|
|
386
386
|
d.day.toString().padStart(2, '0') +
|
|
387
387
|
(!dateonly ? 'T000000' + (floating || timezone ? '' : 'Z') : '')
|