ical-generator 10.1.1-develop.1 → 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/package.json CHANGED
@@ -133,5 +133,5 @@
133
133
  "test": "mocha"
134
134
  },
135
135
  "type": "module",
136
- "version": "10.1.1-develop.1"
136
+ "version": "10.2.0-develop.1"
137
137
  }
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