@hebcal/rest-api 5.2.0 → 6.0.0

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.mjs CHANGED
@@ -1,431 +1,12 @@
1
- /*! @hebcal/rest-api v5.2.0 */
2
- import { parshiot, HDate, flags, HebrewCalendar, version, Zmanim, Locale as Locale$1, gematriya } from '@hebcal/core';
3
- import { getLeyningForParshaHaShavua, getLeyningForHoliday, formatAliyahWithBook } from '@hebcal/leyning';
1
+ /*! @hebcal/rest-api v6.0.0 */
2
+ import { parshiot, HDate, flags, HebrewCalendar, version, Zmanim, Locale, gematriya } from '@hebcal/core';
3
+ import { isoDateString } from '@hebcal/hdate';
4
+ export { pad2, pad4 } from '@hebcal/hdate';
5
+ import { getLeyningForParshaHaShavua } from '@hebcal/leyning/dist/esm/leyning';
6
+ import { getLeyningForHoliday } from '@hebcal/leyning/dist/esm/getLeyningForHoliday';
7
+ import { formatAliyahWithBook } from '@hebcal/leyning/dist/esm/common';
4
8
  import { getTriennialForParshaHaShavua } from '@hebcal/triennial';
5
9
 
6
- /* eslint-disable @typescript-eslint/no-namespace, no-inner-declarations */
7
- /** @private */
8
- const lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
9
- /** @private */
10
- const monthLengths = [lengths, lengths.slice()];
11
- monthLengths[1][2] = 29;
12
- /**
13
- * @private
14
- */
15
- function mod(x, y) {
16
- return x - y * Math.floor(x / y);
17
- }
18
- /**
19
- * @private
20
- */
21
- function quotient(x, y) {
22
- return Math.floor(x / y);
23
- }
24
- /**
25
- * @private
26
- * @param abs - R.D. number of days
27
- */
28
- function yearFromFixed(abs) {
29
- const l0 = abs - 1;
30
- const n400 = quotient(l0, 146097);
31
- const d1 = mod(l0, 146097);
32
- const n100 = quotient(d1, 36524);
33
- const d2 = mod(d1, 36524);
34
- const n4 = quotient(d2, 1461);
35
- const d3 = mod(d2, 1461);
36
- const n1 = quotient(d3, 365);
37
- const year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
38
- return n100 !== 4 && n1 !== 4 ? year + 1 : year;
39
- }
40
- /*
41
- const ABS_14SEP1752 = 639797;
42
- const ABS_2SEP1752 = 639785;
43
- */
44
- /*
45
- * Formerly in namespace, now top-level
46
- */
47
- /**
48
- * Returns true if the Gregorian year is a leap year
49
- * @param year Gregorian year
50
- */
51
- function isGregLeapYear(year) {
52
- return !(year % 4) && (!!(year % 100) || !(year % 400));
53
- }
54
- /**
55
- * Number of days in the Gregorian month for given year
56
- * @param month Gregorian month (1=January, 12=December)
57
- * @param year Gregorian year
58
- */
59
- function daysInGregMonth(month, year) {
60
- // 1 based months
61
- return monthLengths[+isGregLeapYear(year)][month];
62
- }
63
- /**
64
- * Returns true if the object is a Javascript Date
65
- */
66
- function isDate(obj) {
67
- // eslint-disable-next-line no-prototype-builtins
68
- return typeof obj === 'object' && Date.prototype.isPrototypeOf(obj);
69
- }
70
- /**
71
- * @private
72
- * @param year
73
- * @param month (1-12)
74
- * @param day (1-31)
75
- */
76
- function toFixed(year, month, day) {
77
- const py = year - 1;
78
- return (365 * py +
79
- quotient(py, 4) -
80
- quotient(py, 100) +
81
- quotient(py, 400) +
82
- quotient(367 * month - 362, 12) +
83
- (month <= 2 ? 0 : isGregLeapYear(year) ? -1 : -2) +
84
- day);
85
- }
86
- /**
87
- * Converts Gregorian date to absolute R.D. (Rata Die) days
88
- * @param date Gregorian date
89
- */
90
- function greg2abs(date) {
91
- if (!isDate(date)) {
92
- throw new TypeError(`Argument not a Date: ${date}`);
93
- }
94
- const abs = toFixed(date.getFullYear(), date.getMonth() + 1, date.getDate());
95
- /*
96
- if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
97
- throw new RangeError(`Invalid Date: ${date}`);
98
- }
99
- */
100
- return abs;
101
- }
102
- /**
103
- * Converts from Rata Die (R.D. number) to Gregorian date.
104
- * See the footnote on page 384 of ``Calendrical Calculations, Part II:
105
- * Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
106
- * Clamen, Software--Practice and Experience, Volume 23, Number 4
107
- * (April, 1993), pages 383-404 for an explanation.
108
- * @param abs - R.D. number of days
109
- */
110
- function abs2greg(abs) {
111
- if (typeof abs !== 'number') {
112
- throw new TypeError(`Argument not a Number: ${abs}`);
113
- }
114
- abs = Math.trunc(abs);
115
- /*
116
- if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
117
- throw new RangeError(`Invalid Date: ${abs}`);
118
- }
119
- */
120
- const year = yearFromFixed(abs);
121
- const priorDays = abs - toFixed(year, 1, 1);
122
- const correction = abs < toFixed(year, 3, 1) ? 0 : isGregLeapYear(year) ? 1 : 2;
123
- const month = quotient(12 * (priorDays + correction) + 373, 367);
124
- const day = abs - toFixed(year, month, 1) + 1;
125
- const dt = new Date(year, month - 1, day);
126
- if (year < 100 && year >= 0) {
127
- dt.setFullYear(year);
128
- }
129
- return dt;
130
- }
131
-
132
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
133
- /**
134
- * Gregorian date helper functions
135
- */
136
- var greg;
137
- (function (greg) {
138
- })(greg || (greg = {}));
139
- greg.abs2greg = abs2greg;
140
- greg.daysInMonth = daysInGregMonth;
141
- greg.greg2abs = greg2abs;
142
- greg.isDate = isDate;
143
- greg.isLeapYear = isGregLeapYear;
144
-
145
- const alefbet = {
146
- א: 1,
147
- ב: 2,
148
- ג: 3,
149
- ד: 4,
150
- ה: 5,
151
- ו: 6,
152
- ז: 7,
153
- ח: 8,
154
- ט: 9,
155
- י: 10,
156
- כ: 20,
157
- ל: 30,
158
- מ: 40,
159
- נ: 50,
160
- ס: 60,
161
- ע: 70,
162
- פ: 80,
163
- צ: 90,
164
- ק: 100,
165
- ר: 200,
166
- ש: 300,
167
- ת: 400,
168
- };
169
- const heb2num = new Map();
170
- const num2heb = new Map();
171
- for (const [key, val] of Object.entries(alefbet)) {
172
- heb2num.set(key, val);
173
- num2heb.set(val, key);
174
- }
175
-
176
- /**
177
- * Formats a number with leading zeros so the resulting string is 4 digits long.
178
- * Similar to `string.padStart(4, '0')` but will also format
179
- * negative numbers similar to how the JavaScript date formats
180
- * negative year numbers (e.g. `-37` is formatted as `-000037`).
181
- */
182
- function pad4(num) {
183
- if (num < 0) {
184
- return '-00' + pad4(-num);
185
- }
186
- else if (num < 10) {
187
- return '000' + num;
188
- }
189
- else if (num < 100) {
190
- return '00' + num;
191
- }
192
- else if (num < 1000) {
193
- return '0' + num;
194
- }
195
- return String(num);
196
- }
197
- /**
198
- * Formats a number with leading zeros so the resulting string is 2 digits long.
199
- * Similar to `string.padStart(2, '0')`.
200
- */
201
- function pad2(num) {
202
- if (num >= 0 && num < 10) {
203
- return '0' + num;
204
- }
205
- return String(num);
206
- }
207
-
208
- /**
209
- * Returns YYYY-MM-DD in the local timezone
210
- */
211
- function isoDateString(dt) {
212
- return (pad4(dt.getFullYear()) +
213
- '-' +
214
- pad2(dt.getMonth() + 1) +
215
- '-' +
216
- pad2(dt.getDate()));
217
- }
218
-
219
- var poAshkenazi = { "headers": { "plural-forms": "nplurals=2; plural=(n > 1);" }, "contexts": { "": { "Tevet": ["Teves"] } } };
220
-
221
- var poHe = { "headers": { "plural-forms": "nplurals=2; plural=(n > 1);" }, "contexts": { "": { "Adar": ["אַדָר"], "Adar I": ["אַדָר א׳"], "Adar II": ["אַדָר ב׳"], "Av": ["אָב"], "Cheshvan": ["חֶשְׁוָן"], "Elul": ["אֱלוּל"], "Iyyar": ["אִיָיר"], "Kislev": ["כִּסְלֵו"], "Nisan": ["נִיסָן"], "Sh'vat": ["שְׁבָט"], "Sivan": ["סִיוָן"], "Tamuz": ["תַּמּוּז"], "Tevet": ["טֵבֵת"], "Tishrei": ["תִּשְׁרֵי"] } } };
222
-
223
- const noopLocale = {
224
- headers: { 'plural-forms': 'nplurals=2; plural=(n!=1);' },
225
- contexts: { '': {} },
226
- };
227
- const alias = {
228
- h: 'he',
229
- a: 'ashkenazi',
230
- s: 'en',
231
- '': 'en',
232
- };
233
- /** @private */
234
- const locales = new Map();
235
- /** @private */
236
- let activeLocale;
237
- /** @private */
238
- let activeName;
239
- /** @private */
240
- function getEnOrdinal(n) {
241
- const s = ['th', 'st', 'nd', 'rd'];
242
- const v = n % 100;
243
- return n + (s[(v - 20) % 10] || s[v] || s[0]);
244
- }
245
- /** @private */
246
- function checkLocale(locale) {
247
- if (typeof locale !== 'string') {
248
- throw new TypeError(`Invalid locale name: ${locale}`);
249
- }
250
- return locale.toLowerCase();
251
- }
252
- /** @private */
253
- function getExistingLocale(locale) {
254
- const locale1 = checkLocale(locale);
255
- const loc = locales.get(locale1);
256
- if (!loc) {
257
- throw new RangeError(`Locale '${locale}' not found`);
258
- }
259
- return loc;
260
- }
261
- /**
262
- * A locale in Hebcal is used for translations/transliterations of
263
- * holidays. `@hebcal/hdate` supports four locales by default
264
- * * `en` - default, Sephardic transliterations (e.g. "Shabbat")
265
- * * `ashkenazi` - Ashkenazi transliterations (e.g. "Shabbos")
266
- * * `he` - Hebrew (e.g. "שַׁבָּת")
267
- * * `he-x-NoNikud` - Hebrew without nikud (e.g. "שבת")
268
- */
269
- class Locale {
270
- /**
271
- * Returns translation only if `locale` offers a non-empty translation for `id`.
272
- * Otherwise, returns `undefined`.
273
- * @param id Message ID to translate
274
- * @param [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
275
- */
276
- static lookupTranslation(id, locale) {
277
- const loc = (typeof locale === 'string' && locales.get(locale.toLowerCase())) ||
278
- activeLocale;
279
- const array = loc[id];
280
- if ((array === null || array === void 0 ? void 0 : array.length) && array[0].length) {
281
- return array[0];
282
- }
283
- return undefined;
284
- }
285
- /**
286
- * By default, if no translation was found, returns `id`.
287
- * @param id Message ID to translate
288
- * @param [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
289
- */
290
- static gettext(id, locale) {
291
- const text = this.lookupTranslation(id, locale);
292
- if (typeof text === 'undefined') {
293
- return id;
294
- }
295
- return text;
296
- }
297
- /**
298
- * Register locale translations.
299
- * @param locale Locale name (i.e.: `'he'`, `'fr'`)
300
- * @param data parsed data from a `.po` file.
301
- */
302
- static addLocale(locale, data) {
303
- locale = checkLocale(locale);
304
- if (typeof data.contexts !== 'object' ||
305
- typeof data.contexts[''] !== 'object') {
306
- throw new TypeError(`Locale '${locale}' invalid compact format`);
307
- }
308
- locales.set(locale, data.contexts['']);
309
- }
310
- /**
311
- * Adds a translation to `locale`, replacing any previous translation.
312
- * @param locale Locale name (i.e: `'he'`, `'fr'`).
313
- * @param id Message ID to translate
314
- * @param translation Translation text
315
- */
316
- static addTranslation(locale, id, translation) {
317
- const loc = getExistingLocale(locale);
318
- if (typeof id !== 'string' || id.length === 0) {
319
- throw new TypeError(`Invalid id string: ${id}`);
320
- }
321
- const isArray = Array.isArray(translation);
322
- if (isArray) {
323
- const t0 = translation[0];
324
- if (typeof t0 !== 'string' || t0.length === 0) {
325
- throw new TypeError(`Invalid translation array: ${translation}`);
326
- }
327
- }
328
- else if (typeof translation !== 'string') {
329
- throw new TypeError(`Invalid translation string: ${translation}`);
330
- }
331
- loc[id] = isArray ? translation : [translation];
332
- }
333
- /**
334
- * Adds multiple translations to `locale`, replacing any previous translations.
335
- * @param locale Locale name (i.e: `'he'`, `'fr'`).
336
- * @param data parsed data from a `.po` file.
337
- */
338
- static addTranslations(locale, data) {
339
- const loc = getExistingLocale(locale);
340
- if (typeof data.contexts !== 'object' ||
341
- typeof data.contexts[''] !== 'object') {
342
- throw new TypeError(`Locale '${locale}' invalid compact format`);
343
- }
344
- const ctx = data.contexts[''];
345
- Object.assign(loc, ctx);
346
- }
347
- /**
348
- * Activates a locale. Throws an error if the locale has not been previously added.
349
- * After setting the locale to be used, all strings marked for translations
350
- * will be represented by the corresponding translation in the specified locale.
351
- * @param locale Locale name (i.e: `'he'`, `'fr'`)
352
- */
353
- static useLocale(locale) {
354
- const locale0 = checkLocale(locale);
355
- const obj = getExistingLocale(locale0);
356
- activeName = alias[locale0] || locale0;
357
- activeLocale = obj;
358
- return activeLocale;
359
- }
360
- /**
361
- * Returns the name of the active locale (i.e. 'he', 'ashkenazi', 'fr')
362
- */
363
- static getLocaleName() {
364
- return activeName;
365
- }
366
- /**
367
- * Returns the names of registered locales
368
- */
369
- static getLocaleNames() {
370
- const keys = Array.from(locales.keys());
371
- return keys.sort((a, b) => a.localeCompare(b));
372
- }
373
- /**
374
- * Renders a number in ordinal, such as 1st, 2nd or 3rd
375
- * @param [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
376
- */
377
- static ordinal(n, locale) {
378
- const locale1 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
379
- const locale0 = locale1 || activeName;
380
- if (!locale0) {
381
- return getEnOrdinal(n);
382
- }
383
- switch (locale0) {
384
- case 'en':
385
- case 's':
386
- case 'a':
387
- return getEnOrdinal(n);
388
- case 'es':
389
- return n + 'º';
390
- case 'h':
391
- case 'he':
392
- case 'he-x-nonikud':
393
- return String(n);
394
- }
395
- if (locale0.startsWith('ashkenazi')) {
396
- return getEnOrdinal(n);
397
- }
398
- return n + '.';
399
- }
400
- /**
401
- * Removes nekudot from Hebrew string
402
- */
403
- static hebrewStripNikkud(str) {
404
- return str.replace(/[\u0590-\u05bd]/g, '').replace(/[\u05bf-\u05c7]/g, '');
405
- }
406
- }
407
- Locale.addLocale('en', noopLocale);
408
- Locale.addLocale('s', noopLocale);
409
- Locale.addLocale('', noopLocale);
410
- Locale.useLocale('en');
411
- /* Ashkenazic transliterations */
412
- Locale.addLocale('ashkenazi', poAshkenazi);
413
- Locale.addLocale('a', poAshkenazi);
414
- /* Hebrew with nikkud */
415
- Locale.addLocale('he', poHe);
416
- Locale.addLocale('h', poHe);
417
- /* Hebrew without nikkud */
418
- const heStrs = poHe.contexts[''];
419
- const heNoNikud = {};
420
- for (const [key, val] of Object.entries(heStrs)) {
421
- heNoNikud[key] = [Locale.hebrewStripNikkud(val[0])];
422
- }
423
- const poHeNoNikud = {
424
- headers: poHe.headers,
425
- contexts: { '': heNoNikud },
426
- };
427
- Locale.addLocale('he-x-NoNikud', poHeNoNikud);
428
-
429
10
  var countryNames0 = {
430
11
  "AD": "Andorra",
431
12
  "AE": "United Arab Emirates",
@@ -1229,7 +810,7 @@ function eventToClassicApiObject(ev, options, leyning = true) {
1229
810
  }
1230
811
  const hebrew = ev.renderBrief('he');
1231
812
  if (hebrew) {
1232
- result.hebrew = Locale$1.hebrewStripNikkud(hebrew);
813
+ result.hebrew = Locale.hebrewStripNikkud(hebrew);
1233
814
  }
1234
815
  if (!candles) {
1235
816
  if (leyning) {
@@ -1291,7 +872,7 @@ function eventToClassicApiObject(ev, options, leyning = true) {
1291
872
  const dd = hd.getDate();
1292
873
  result.heDateParts = {
1293
874
  y: gematriya(yy),
1294
- m: Locale$1.gettext(mm, 'he-x-NoNikud'),
875
+ m: Locale.gettext(mm, 'he-x-NoNikud'),
1295
876
  d: gematriya(dd),
1296
877
  };
1297
878
  }
@@ -1448,7 +1029,7 @@ function eventToRssItem2(ev, options) {
1448
1029
  if (candles) {
1449
1030
  const colon = subj.indexOf(': ');
1450
1031
  if (colon !== -1) {
1451
- const options = { location, il, locale: Locale$1.getLocaleName() };
1032
+ const options = { location, il, locale: Locale.getLocaleName() };
1452
1033
  const time = HebrewCalendar.reformatTimeStr(ev.eventTimeStr, 'pm', options);
1453
1034
  subj = subj.substring(0, colon) + ': ' + time;
1454
1035
  }
@@ -1497,7 +1078,7 @@ function eventToFullCalendar(ev, tzid, il) {
1497
1078
  };
1498
1079
  const hebrew = ev.renderBrief('he');
1499
1080
  if (hebrew) {
1500
- result.hebrew = Locale$1.hebrewStripNikkud(hebrew);
1081
+ result.hebrew = Locale.hebrewStripNikkud(hebrew);
1501
1082
  }
1502
1083
  const url = ev.url();
1503
1084
  if (url) {
@@ -1517,4 +1098,4 @@ function eventToFullCalendar(ev, tzid, il) {
1517
1098
  return result;
1518
1099
  }
1519
1100
 
1520
- export { appendIsraelAndTracking, countryNames, eventToClassicApiObject, eventToCsv, eventToFullCalendar, eventToRssItem2, eventsToClassicApi, eventsToCsv, eventsToRss2, getCalendarTitle, getDownloadFilename, getEventCategories, getHolidayDescription, holidayDescription, locationToPlainObj, makeAnchor, makeMemo, makeTorahMemoText, pad2, pad4, renderTitleWithoutTime, shouldRenderBrief, toISOString };
1101
+ export { appendIsraelAndTracking, countryNames, eventToClassicApiObject, eventToCsv, eventToFullCalendar, eventToRssItem2, eventsToClassicApi, eventsToCsv, eventsToRss2, getCalendarTitle, getDownloadFilename, getEventCategories, getHolidayDescription, holidayDescription, locationToPlainObj, makeAnchor, makeMemo, makeTorahMemoText, renderTitleWithoutTime, shouldRenderBrief, toISOString };
package/package.json CHANGED
@@ -1,20 +1,18 @@
1
1
  {
2
2
  "name": "@hebcal/rest-api",
3
- "version": "5.2.0",
3
+ "version": "6.0.0",
4
4
  "author": "Michael J. Radwin (https://github.com/mjradwin)",
5
5
  "keywords": [
6
6
  "hebcal"
7
7
  ],
8
8
  "description": "Jewish holidays and Hebrew calendar as plain JSON objects and CSV export",
9
9
  "engines": {
10
- "node": ">= 16.0.0"
10
+ "node": ">= 18.0.0"
11
11
  },
12
- "main": "dist/index.cjs",
13
12
  "module": "dist/index.mjs",
14
13
  "type": "module",
15
14
  "exports": {
16
15
  "import": "./dist/index.mjs",
17
- "require": "./dist/index.cjs",
18
16
  "types": "./dist/module.d.ts"
19
17
  },
20
18
  "typings": "dist/module.d.ts",
@@ -29,9 +27,9 @@
29
27
  "url": "https://github.com/hebcal/hebcal-rest-api/issues"
30
28
  },
31
29
  "dependencies": {
32
- "@hebcal/core": "^5.5.2",
33
- "@hebcal/hdate": "^0.11.5",
34
- "@hebcal/leyning": "^8.2.7",
30
+ "@hebcal/core": "^5.7.7",
31
+ "@hebcal/hdate": "^0.12.0",
32
+ "@hebcal/leyning": "^9.0.1",
35
33
  "@hebcal/triennial": "^5.1.3"
36
34
  },
37
35
  "scripts": {
@@ -49,21 +47,20 @@
49
47
  },
50
48
  "license": "BSD-2-Clause",
51
49
  "devDependencies": {
52
- "@babel/preset-env": "^7.25.8",
53
- "@babel/preset-typescript": "^7.25.7",
54
- "@hebcal/learning": "^5.1.1",
50
+ "@babel/preset-env": "^7.26.0",
51
+ "@babel/preset-typescript": "^7.26.0",
52
+ "@hebcal/learning": "^5.1.2",
55
53
  "@rollup/plugin-commonjs": "^28.0.1",
56
54
  "@rollup/plugin-json": "^6.1.0",
57
55
  "@rollup/plugin-node-resolve": "^15.3.0",
58
56
  "@rollup/plugin-terser": "^0.4.4",
59
57
  "@rollup/plugin-typescript": "^12.1.1",
60
- "@types/jest": "^29.5.13",
58
+ "@types/jest": "^29.5.14",
61
59
  "gts": "^5.3.1",
62
60
  "jest": "^29.7.0",
63
- "rollup": "^4.24.0",
64
- "rollup-plugin-dts": "^6.1.1",
61
+ "rollup": "^4.24.4",
65
62
  "ts-jest": "^29.2.5",
66
- "typedoc": "^0.26.10",
63
+ "typedoc": "^0.26.11",
67
64
  "typescript": "^5.6.3"
68
65
  }
69
66
  }