@hebcal/icalendar 7.0.4 → 7.0.6

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/foldLine.js CHANGED
@@ -49,9 +49,7 @@ export function foldLine(line) {
49
49
  // lineBytes/74 of them, so we ask it about those offsets via
50
50
  // `containing()` rather than iterating every cluster in the line --
51
51
  // the same fold points for a fraction of the work.
52
- if (!foldSegmenter) {
53
- foldSegmenter = new Intl.Segmenter('en', { granularity: 'grapheme' });
54
- }
52
+ foldSegmenter ??= new Intl.Segmenter('en', { granularity: 'grapheme' });
55
53
  const segments = foldSegmenter.segment(line);
56
54
  const parts = [];
57
55
  const n = line.length;
@@ -1,5 +1,5 @@
1
- import { Event } from '@hebcal/core/dist/esm/event';
2
- import { CalOptions } from '@hebcal/core/dist/esm/CalOptions';
1
+ import type { Event } from '@hebcal/core/dist/esm/event';
2
+ import type { CalOptions } from '@hebcal/core/dist/esm/CalOptions';
3
3
  export type ICalEventOptions = {
4
4
  dtstamp?: string;
5
5
  sequence?: number;
package/dist/icalendar.js CHANGED
@@ -1,4 +1,3 @@
1
- import { flags } from '@hebcal/core/dist/esm/event';
2
1
  import { Locale } from '@hebcal/core/dist/esm/locale';
3
2
  import { murmur32HexSync } from '@hebcal/murmurhash3';
4
3
  import { pad2, pad4, isDate } from '@hebcal/hdate';
@@ -27,6 +26,14 @@ const CATEGORY = {
27
26
  user: 'Personal',
28
27
  zmanim: null,
29
28
  };
29
+ /**
30
+ * Narrows `isDate()` from `@hebcal/hdate` (which returns a plain boolean)
31
+ * into a type guard.
32
+ * @private
33
+ */
34
+ function isDateObj(obj) {
35
+ return isDate(obj);
36
+ }
30
37
  /**
31
38
  * @private
32
39
  */
@@ -52,13 +59,8 @@ function appendTrackingToUrl(url, options) {
52
59
  }
53
60
  const utmMedium = options.utmMedium || 'icalendar';
54
61
  const utmCampaign = options.utmCampaign;
55
- return appendIsraelAndTracking(url, options.il, utmSource, utmMedium, utmCampaign);
62
+ return appendIsraelAndTracking(url, Boolean(options.il), utmSource, utmMedium, utmCampaign);
56
63
  }
57
- const DAILY_LEARNING = flags.DAILY_LEARNING |
58
- flags.DAF_YOMI |
59
- flags.MISHNA_YOMI |
60
- flags.YERUSHALMI_YOMI |
61
- flags.NACH_YOMI;
62
64
  /** Formats a date-time string as `YYYYMMDDTHHMMSS` */
63
65
  function rfc5545DateTime(dt, hour, minute) {
64
66
  return IcalEvent.formatYYYYMMDD(dt) + 'T' + pad2(hour) + pad2(minute) + '00';
@@ -117,7 +119,6 @@ export class IcalEvent {
117
119
  const opts = { ...options };
118
120
  this.options = opts;
119
121
  this.dtstamp = opts.dtstamp || IcalEvent.makeDtstamp(new Date());
120
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
121
122
  const ev0 = ev;
122
123
  if (typeof ev0.sequence === 'number') {
123
124
  this.sequence = ev0.sequence;
@@ -131,14 +132,14 @@ export class IcalEvent {
131
132
  let subj = shouldRenderBrief(ev)
132
133
  ? ev.renderBrief(locale)
133
134
  : ev.render(locale);
134
- const mask = ev.getFlags();
135
135
  if (ev0.locationName) {
136
136
  this.locationName = ev0.locationName;
137
137
  }
138
138
  else if (timed && location) {
139
139
  this.locationName = location.getShortName();
140
140
  }
141
- else if (mask & DAILY_LEARNING && ev0.category) {
141
+ else if (ev.hasAnyFlag('DAILY_LEARNING', 'DAF_YOMI', 'MISHNA_YOMI', 'YERUSHALMI_YOMI', 'NACH_YOMI') &&
142
+ ev0.category) {
142
143
  this.locationName = Locale.gettext(ev0.category, locale);
143
144
  }
144
145
  const hd = ev.getDate();
@@ -161,7 +162,7 @@ export class IcalEvent {
161
162
  // It's more compatible with everthing except ancient versions of
162
163
  // Lotus Notes circa 2004
163
164
  this.dtargs = ';VALUE=DATE';
164
- if (mask & flags.CHAG) {
165
+ if (ev.hasFlag('CHAG')) {
165
166
  this.transp = 'OPAQUE';
166
167
  this.busyStatus = 'OOF';
167
168
  }
@@ -169,7 +170,7 @@ export class IcalEvent {
169
170
  if (opts.emoji) {
170
171
  const prefix = ev.getEmoji();
171
172
  if (prefix) {
172
- if (mask & flags.OMER_COUNT) {
173
+ if (ev.hasFlag('OMER_COUNT')) {
173
174
  subj = subj + ' ' + prefix;
174
175
  }
175
176
  else {
@@ -187,28 +188,27 @@ export class IcalEvent {
187
188
  }
188
189
  this.subj = subj;
189
190
  this.category =
190
- ev0.category ||
191
- (CATEGORY[getEventCategories(ev)?.[0]] ?? null);
191
+ ev0.category || (CATEGORY[getEventCategories(ev)[0]] ?? null);
192
192
  }
193
193
  getAlarm() {
194
194
  const ev = this.ev;
195
- const mask = ev.getFlags();
196
195
  const evAlarm = ev.alarm;
197
196
  if (typeof evAlarm === 'string') {
198
197
  return 'TRIGGER:' + evAlarm;
199
198
  }
200
- else if (typeof evAlarm === 'boolean' && !evAlarm) {
199
+ else if (evAlarm === false) {
201
200
  return null;
202
201
  }
203
- else if (isDate(evAlarm)) {
204
- const alarmDt = evAlarm;
202
+ else if (isDateObj(evAlarm)) {
203
+ // copy so we don't mutate the caller's Date
204
+ const alarmDt = new Date(evAlarm);
205
205
  alarmDt.setSeconds(0);
206
206
  return 'TRIGGER;VALUE=DATE-TIME:' + IcalEvent.makeDtstamp(alarmDt);
207
207
  }
208
- else if (mask & flags.OMER_COUNT) {
208
+ else if (ev.hasFlag('OMER_COUNT')) {
209
209
  return 'TRIGGER:-P0DT3H30M0S'; // 8:30pm Omer alarm evening before
210
210
  }
211
- else if (mask & flags.USER_EVENT) {
211
+ else if (ev.hasFlag('USER_EVENT')) {
212
212
  return 'TRIGGER:-P0DT12H0M0S'; // noon the day before
213
213
  }
214
214
  else if (this.timed && ev.getDesc().startsWith('Candle lighting')) {
@@ -217,20 +217,21 @@ export class IcalEvent {
217
217
  return null;
218
218
  }
219
219
  getUid() {
220
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
221
- let uid = this.ev.uid;
222
- if (uid) {
223
- return uid;
220
+ const ev = this.ev;
221
+ if (ev.uid) {
222
+ return ev.uid;
224
223
  }
225
- const digest = murmur32HexSync(this.ev.getDesc());
226
- uid = `hebcal-${this.isoDateOnly}-${digest}`;
224
+ const digest = murmur32HexSync(ev.getDesc());
225
+ let uid = `hebcal-${this.isoDateOnly}-${digest}`;
227
226
  const loc = this.options.location;
228
227
  if (this.timed && loc) {
229
- if (loc.getGeoId()) {
230
- uid += `-${loc.getGeoId()}`;
228
+ const geoId = loc.getGeoId();
229
+ const name = loc.getName();
230
+ if (geoId) {
231
+ uid += `-${geoId}`;
231
232
  }
232
- else if (loc.getName()) {
233
- uid += '-' + makeAnchor(loc.getName());
233
+ else if (name) {
234
+ uid += '-' + makeAnchor(name);
234
235
  }
235
236
  }
236
237
  return uid;
@@ -238,27 +239,24 @@ export class IcalEvent {
238
239
  getLongLines() {
239
240
  if (this.lines)
240
241
  return this.lines;
241
- const categoryLine = this.category ? [`CATEGORIES:${this.category}`] : [];
242
242
  const uid = this.getUid();
243
- if (this.sequence) {
244
- categoryLine.unshift(`SEQUENCE:${this.sequence}`);
245
- }
246
- const arr = (this.lines = ['BEGIN:VEVENT', `DTSTAMP:${this.dtstamp}`]
247
- .concat(categoryLine)
248
- .concat([
243
+ const arr = (this.lines = [
244
+ 'BEGIN:VEVENT',
245
+ `DTSTAMP:${this.dtstamp}`,
246
+ ...(this.sequence ? [`SEQUENCE:${this.sequence}`] : []),
247
+ ...(this.category ? [`CATEGORIES:${this.category}`] : []),
249
248
  `SUMMARY:${this.subj}`,
250
249
  `DTSTART${this.dtargs}:${this.startDate}`,
251
250
  `DTEND${this.dtargs}:${this.endDate}`,
252
251
  `UID:${uid}`,
253
252
  `TRANSP:${this.transp}`,
254
253
  `X-MICROSOFT-CDO-BUSYSTATUS:${this.busyStatus}`,
255
- ]));
254
+ ]);
256
255
  if (!this.timed) {
257
256
  arr.push('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE');
258
257
  }
259
258
  const ev = this.ev;
260
- const mask = ev.getFlags();
261
- const isUserEvent = Boolean(mask & flags.USER_EVENT);
259
+ const isUserEvent = ev.hasFlag('USER_EVENT');
262
260
  if (!isUserEvent) {
263
261
  arr.push('CLASS:PUBLIC');
264
262
  }
@@ -285,7 +283,7 @@ export class IcalEvent {
285
283
  }
286
284
  const trigger = this.getAlarm();
287
285
  if (trigger) {
288
- arr.push('BEGIN:VALARM', 'ACTION:DISPLAY', 'DESCRIPTION:Event reminder', `${trigger}`, 'END:VALARM');
286
+ arr.push('BEGIN:VALARM', 'ACTION:DISPLAY', 'DESCRIPTION:Event reminder', trigger, 'END:VALARM');
289
287
  }
290
288
  arr.push('END:VEVENT');
291
289
  return arr;
@@ -1 +1 @@
1
- export declare const version = "7.0.4";
1
+ export declare const version = "7.0.6";
@@ -1,2 +1,2 @@
1
1
  // DO NOT EDIT THIS AUTO-GENERATED FILE!
2
- export const version = '7.0.4';
2
+ export const version = '7.0.6';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hebcal/icalendar",
3
- "version": "7.0.4",
3
+ "version": "7.0.6",
4
4
  "author": "Michael J. Radwin (https://github.com/mjradwin)",
5
5
  "keywords": [
6
6
  "ical",
@@ -30,17 +30,18 @@
30
30
  },
31
31
  "homepage": "https://hebcal.github.io/api/icalendar/",
32
32
  "dependencies": {
33
- "@hebcal/core": "^6.9.3",
34
- "@hebcal/hdate": "^0.22.8",
33
+ "@hebcal/core": "^6.13.0",
34
+ "@hebcal/hdate": "^0.23.0",
35
35
  "@hebcal/murmurhash3": "^1.0.0",
36
- "@hebcal/rest-api": "^7.1.3"
36
+ "@hebcal/rest-api": "^7.2.1"
37
37
  },
38
38
  "scripts": {
39
39
  "build:version": "node ./version.js package.json src/pkgVersion.ts",
40
40
  "build": "npm run build:version && tsc",
41
41
  "pretest": "npm run build",
42
42
  "docs": "npx -y typedoc",
43
- "test": "vitest",
43
+ "test": "vitest run",
44
+ "test:watch": "vitest",
44
45
  "lint": "oxlint && prettier --check .",
45
46
  "clean": "rm -rf dist",
46
47
  "compile": "tsc",
@@ -48,11 +49,11 @@
48
49
  },
49
50
  "license": "BSD-2-Clause",
50
51
  "devDependencies": {
51
- "@hebcal/learning": "^6.11.3",
52
- "@types/node": "26.6.2",
53
- "oxlint": "^1.83.0",
54
- "prettier": "^3.9.8",
52
+ "@hebcal/learning": "^6.12.0",
53
+ "@types/node": "26.6.4",
54
+ "oxlint": "^1.86.0",
55
+ "prettier": "^3.9.9",
55
56
  "typescript": "^7.0.2",
56
- "vitest": "^5.0.1"
57
+ "vitest": "^5.0.3"
57
58
  }
58
59
  }