@hebcal/icalendar 4.21.0 → 5.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.js +41 -39
- package/dist/index.mjs +41 -39
- package/package.json +12 -16
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @hebcal/icalendar
|
|
1
|
+
/*! @hebcal/icalendar v5.0.0 */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var core = require('@hebcal/core');
|
|
@@ -6,7 +6,7 @@ var murmurhash3 = require('murmurhash3');
|
|
|
6
6
|
var restApi = require('@hebcal/rest-api');
|
|
7
7
|
var fs = require('fs');
|
|
8
8
|
|
|
9
|
-
const version="
|
|
9
|
+
const version="5.0.0";
|
|
10
10
|
|
|
11
11
|
const VTIMEZONE = {};
|
|
12
12
|
const CATEGORY = {
|
|
@@ -43,7 +43,7 @@ function addOptional(arr, key, val) {
|
|
|
43
43
|
/**
|
|
44
44
|
* @private
|
|
45
45
|
* @param {string} url
|
|
46
|
-
* @param {
|
|
46
|
+
* @param {CalOptions} options
|
|
47
47
|
* @return {string}
|
|
48
48
|
*/
|
|
49
49
|
function appendTrackingToUrl(url, options) {
|
|
@@ -65,7 +65,7 @@ class IcalEvent {
|
|
|
65
65
|
/**
|
|
66
66
|
* Builds an IcalEvent object from a Hebcal Event
|
|
67
67
|
* @param {Event} ev
|
|
68
|
-
* @param {
|
|
68
|
+
* @param {CalOptions} options
|
|
69
69
|
*/
|
|
70
70
|
constructor(ev, options = {}) {
|
|
71
71
|
this.ev = ev;
|
|
@@ -90,9 +90,8 @@ class IcalEvent {
|
|
|
90
90
|
this.locationName = core.Locale.gettext('Nach Yomi');
|
|
91
91
|
} else if (mask & core.flags.MISHNA_YOMI) {
|
|
92
92
|
this.locationName = core.Locale.gettext('Mishna Yomi');
|
|
93
|
-
} else if (timed && options.location
|
|
94
|
-
|
|
95
|
-
this.locationName = comma == -1 ? options.location.name : options.location.name.substring(0, comma);
|
|
93
|
+
} else if (timed && options.location) {
|
|
94
|
+
this.locationName = options.location.getShortName();
|
|
96
95
|
}
|
|
97
96
|
const date = IcalEvent.formatYYYYMMDD(ev.getDate().greg());
|
|
98
97
|
this.startDate = date;
|
|
@@ -105,8 +104,8 @@ class IcalEvent {
|
|
|
105
104
|
minute = +minute;
|
|
106
105
|
this.startDate += 'T' + restApi.pad2(hour) + restApi.pad2(minute) + '00';
|
|
107
106
|
this.endDate = this.startDate;
|
|
108
|
-
if (options.location
|
|
109
|
-
this.dtargs = `;TZID=${options.location.
|
|
107
|
+
if (options.location?.getTzid()) {
|
|
108
|
+
this.dtargs = `;TZID=${options.location.getTzid()}`;
|
|
110
109
|
}
|
|
111
110
|
} else {
|
|
112
111
|
this.endDate = IcalEvent.formatYYYYMMDD(ev.getDate().next().greg());
|
|
@@ -174,10 +173,11 @@ class IcalEvent {
|
|
|
174
173
|
const digest = murmurhash3.murmur32HexSync(this.ev.getDesc());
|
|
175
174
|
let uid = `hebcal-${this.startDate}-${digest}`;
|
|
176
175
|
if (this.timed && options.location) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
const loc = options.location;
|
|
177
|
+
if (loc.getGeoId()) {
|
|
178
|
+
uid += `-${loc.getGeoId()}`;
|
|
179
|
+
} else if (loc.getName()) {
|
|
180
|
+
uid += '-' + restApi.makeAnchor(loc.getName());
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
return uid;
|
|
@@ -209,7 +209,7 @@ class IcalEvent {
|
|
|
209
209
|
addOptional(arr, 'DESCRIPTION', memo);
|
|
210
210
|
addOptional(arr, 'LOCATION', this.locationName);
|
|
211
211
|
if (this.timed && options.location) {
|
|
212
|
-
arr.push('GEO:' + options.location.
|
|
212
|
+
arr.push('GEO:' + options.location.getLatitude() + ';' + options.location.getLongitude());
|
|
213
213
|
}
|
|
214
214
|
const trigger = this.getAlarm();
|
|
215
215
|
if (trigger) {
|
|
@@ -317,7 +317,7 @@ class IcalEvent {
|
|
|
317
317
|
/**
|
|
318
318
|
* Transforms a single Event into a VEVENT string
|
|
319
319
|
* @param {Event} ev
|
|
320
|
-
* @param {
|
|
320
|
+
* @param {CalOptions} options
|
|
321
321
|
* @return {string} multi-line result, delimited by \r\n
|
|
322
322
|
*/
|
|
323
323
|
function eventToIcal(ev, options) {
|
|
@@ -354,17 +354,17 @@ function makeTorahMemo(ev, il) {
|
|
|
354
354
|
/**
|
|
355
355
|
* @private
|
|
356
356
|
* @param {Event} e
|
|
357
|
-
* @param {
|
|
357
|
+
* @param {CalOptions} options
|
|
358
358
|
* @return {string}
|
|
359
359
|
*/
|
|
360
360
|
function createMemo(e, options) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
e.memo = e.memo.replace(/\n/g, '\\n');
|
|
361
|
+
let memo = e.memo;
|
|
362
|
+
if (typeof memo === 'string' && memo.length && memo.indexOf('\n') !== -1) {
|
|
363
|
+
memo = memo.replace(/\n/g, '\\n');
|
|
365
364
|
}
|
|
366
|
-
|
|
367
|
-
|
|
365
|
+
const desc = e.getDesc();
|
|
366
|
+
if (desc === 'Havdalah' || desc === 'Candle lighting') {
|
|
367
|
+
return memo || '';
|
|
368
368
|
}
|
|
369
369
|
const mask = e.getFlags();
|
|
370
370
|
if (mask & core.flags.OMER_COUNT) {
|
|
@@ -373,30 +373,32 @@ function createMemo(e, options) {
|
|
|
373
373
|
}
|
|
374
374
|
const url = appendTrackingToUrl(e.url(), options);
|
|
375
375
|
const torahMemo = makeTorahMemo(e, options.il);
|
|
376
|
-
if (
|
|
377
|
-
|
|
378
|
-
} else {
|
|
379
|
-
let memo = e.memo || restApi.getHolidayDescription(e);
|
|
380
|
-
if (!memo && typeof e.linkedEvent !== 'undefined') {
|
|
376
|
+
if (!memo) {
|
|
377
|
+
if (typeof e.linkedEvent !== 'undefined') {
|
|
381
378
|
memo = e.linkedEvent.render(options.locale);
|
|
379
|
+
} else {
|
|
380
|
+
memo = restApi.getHolidayDescription(e);
|
|
382
381
|
}
|
|
383
|
-
|
|
384
|
-
|
|
382
|
+
}
|
|
383
|
+
if (torahMemo) {
|
|
384
|
+
if (memo.length) {
|
|
385
|
+
memo += '\\n\\n';
|
|
385
386
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
memo +=
|
|
387
|
+
memo += torahMemo;
|
|
388
|
+
}
|
|
389
|
+
if (url) {
|
|
390
|
+
if (memo.length) {
|
|
391
|
+
memo += '\\n\\n';
|
|
391
392
|
}
|
|
392
|
-
|
|
393
|
+
memo += url;
|
|
393
394
|
}
|
|
395
|
+
return memo;
|
|
394
396
|
}
|
|
395
397
|
|
|
396
398
|
/**
|
|
397
399
|
* Generates an RFC 2445 iCalendar string from an array of events
|
|
398
400
|
* @param {Event[]} events
|
|
399
|
-
* @param {
|
|
401
|
+
* @param {CalOptions} options
|
|
400
402
|
* @return {Promise<string>}
|
|
401
403
|
*/
|
|
402
404
|
async function eventsToIcalendar(events, options) {
|
|
@@ -414,7 +416,7 @@ async function eventsToIcalendar(events, options) {
|
|
|
414
416
|
/**
|
|
415
417
|
* Generates an RFC 2445 iCalendar string from an array of IcalEvents
|
|
416
418
|
* @param {IcalEvent[]} icals
|
|
417
|
-
* @param {
|
|
419
|
+
* @param {CalOptions} options
|
|
418
420
|
* @return {Promise<string>}
|
|
419
421
|
*/
|
|
420
422
|
async function icalEventsToString(icals, options) {
|
|
@@ -444,8 +446,8 @@ async function icalEventsToString(icals, options) {
|
|
|
444
446
|
stream.push(`X-APPLE-CALENDAR-COLOR:${opts.calendarColor}\r\n`);
|
|
445
447
|
}
|
|
446
448
|
const location = opts.location;
|
|
447
|
-
|
|
448
|
-
|
|
449
|
+
const tzid = location?.getTzid();
|
|
450
|
+
if (tzid) {
|
|
449
451
|
stream.push(`X-WR-TIMEZONE;VALUE=TEXT:${tzid}\r\n`);
|
|
450
452
|
if (VTIMEZONE[tzid]) {
|
|
451
453
|
stream.push(VTIMEZONE[tzid]);
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/*! @hebcal/icalendar
|
|
1
|
+
/*! @hebcal/icalendar v5.0.0 */
|
|
2
2
|
import { flags, Locale, greg } from '@hebcal/core';
|
|
3
3
|
import { murmur32HexSync } from 'murmurhash3';
|
|
4
4
|
import { shouldRenderBrief, pad2, getEventCategories, makeAnchor, pad4, getHolidayDescription, getCalendarTitle, appendIsraelAndTracking, makeTorahMemoText } from '@hebcal/rest-api';
|
|
5
5
|
import { promises } from 'fs';
|
|
6
6
|
|
|
7
|
-
const version="
|
|
7
|
+
const version="5.0.0";
|
|
8
8
|
|
|
9
9
|
const VTIMEZONE = {};
|
|
10
10
|
const CATEGORY = {
|
|
@@ -41,7 +41,7 @@ function addOptional(arr, key, val) {
|
|
|
41
41
|
/**
|
|
42
42
|
* @private
|
|
43
43
|
* @param {string} url
|
|
44
|
-
* @param {
|
|
44
|
+
* @param {CalOptions} options
|
|
45
45
|
* @return {string}
|
|
46
46
|
*/
|
|
47
47
|
function appendTrackingToUrl(url, options) {
|
|
@@ -63,7 +63,7 @@ class IcalEvent {
|
|
|
63
63
|
/**
|
|
64
64
|
* Builds an IcalEvent object from a Hebcal Event
|
|
65
65
|
* @param {Event} ev
|
|
66
|
-
* @param {
|
|
66
|
+
* @param {CalOptions} options
|
|
67
67
|
*/
|
|
68
68
|
constructor(ev, options = {}) {
|
|
69
69
|
this.ev = ev;
|
|
@@ -88,9 +88,8 @@ class IcalEvent {
|
|
|
88
88
|
this.locationName = Locale.gettext('Nach Yomi');
|
|
89
89
|
} else if (mask & flags.MISHNA_YOMI) {
|
|
90
90
|
this.locationName = Locale.gettext('Mishna Yomi');
|
|
91
|
-
} else if (timed && options.location
|
|
92
|
-
|
|
93
|
-
this.locationName = comma == -1 ? options.location.name : options.location.name.substring(0, comma);
|
|
91
|
+
} else if (timed && options.location) {
|
|
92
|
+
this.locationName = options.location.getShortName();
|
|
94
93
|
}
|
|
95
94
|
const date = IcalEvent.formatYYYYMMDD(ev.getDate().greg());
|
|
96
95
|
this.startDate = date;
|
|
@@ -103,8 +102,8 @@ class IcalEvent {
|
|
|
103
102
|
minute = +minute;
|
|
104
103
|
this.startDate += 'T' + pad2(hour) + pad2(minute) + '00';
|
|
105
104
|
this.endDate = this.startDate;
|
|
106
|
-
if (options.location
|
|
107
|
-
this.dtargs = `;TZID=${options.location.
|
|
105
|
+
if (options.location?.getTzid()) {
|
|
106
|
+
this.dtargs = `;TZID=${options.location.getTzid()}`;
|
|
108
107
|
}
|
|
109
108
|
} else {
|
|
110
109
|
this.endDate = IcalEvent.formatYYYYMMDD(ev.getDate().next().greg());
|
|
@@ -172,10 +171,11 @@ class IcalEvent {
|
|
|
172
171
|
const digest = murmur32HexSync(this.ev.getDesc());
|
|
173
172
|
let uid = `hebcal-${this.startDate}-${digest}`;
|
|
174
173
|
if (this.timed && options.location) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
174
|
+
const loc = options.location;
|
|
175
|
+
if (loc.getGeoId()) {
|
|
176
|
+
uid += `-${loc.getGeoId()}`;
|
|
177
|
+
} else if (loc.getName()) {
|
|
178
|
+
uid += '-' + makeAnchor(loc.getName());
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
return uid;
|
|
@@ -207,7 +207,7 @@ class IcalEvent {
|
|
|
207
207
|
addOptional(arr, 'DESCRIPTION', memo);
|
|
208
208
|
addOptional(arr, 'LOCATION', this.locationName);
|
|
209
209
|
if (this.timed && options.location) {
|
|
210
|
-
arr.push('GEO:' + options.location.
|
|
210
|
+
arr.push('GEO:' + options.location.getLatitude() + ';' + options.location.getLongitude());
|
|
211
211
|
}
|
|
212
212
|
const trigger = this.getAlarm();
|
|
213
213
|
if (trigger) {
|
|
@@ -315,7 +315,7 @@ class IcalEvent {
|
|
|
315
315
|
/**
|
|
316
316
|
* Transforms a single Event into a VEVENT string
|
|
317
317
|
* @param {Event} ev
|
|
318
|
-
* @param {
|
|
318
|
+
* @param {CalOptions} options
|
|
319
319
|
* @return {string} multi-line result, delimited by \r\n
|
|
320
320
|
*/
|
|
321
321
|
function eventToIcal(ev, options) {
|
|
@@ -352,17 +352,17 @@ function makeTorahMemo(ev, il) {
|
|
|
352
352
|
/**
|
|
353
353
|
* @private
|
|
354
354
|
* @param {Event} e
|
|
355
|
-
* @param {
|
|
355
|
+
* @param {CalOptions} options
|
|
356
356
|
* @return {string}
|
|
357
357
|
*/
|
|
358
358
|
function createMemo(e, options) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
e.memo = e.memo.replace(/\n/g, '\\n');
|
|
359
|
+
let memo = e.memo;
|
|
360
|
+
if (typeof memo === 'string' && memo.length && memo.indexOf('\n') !== -1) {
|
|
361
|
+
memo = memo.replace(/\n/g, '\\n');
|
|
363
362
|
}
|
|
364
|
-
|
|
365
|
-
|
|
363
|
+
const desc = e.getDesc();
|
|
364
|
+
if (desc === 'Havdalah' || desc === 'Candle lighting') {
|
|
365
|
+
return memo || '';
|
|
366
366
|
}
|
|
367
367
|
const mask = e.getFlags();
|
|
368
368
|
if (mask & flags.OMER_COUNT) {
|
|
@@ -371,30 +371,32 @@ function createMemo(e, options) {
|
|
|
371
371
|
}
|
|
372
372
|
const url = appendTrackingToUrl(e.url(), options);
|
|
373
373
|
const torahMemo = makeTorahMemo(e, options.il);
|
|
374
|
-
if (
|
|
375
|
-
|
|
376
|
-
} else {
|
|
377
|
-
let memo = e.memo || getHolidayDescription(e);
|
|
378
|
-
if (!memo && typeof e.linkedEvent !== 'undefined') {
|
|
374
|
+
if (!memo) {
|
|
375
|
+
if (typeof e.linkedEvent !== 'undefined') {
|
|
379
376
|
memo = e.linkedEvent.render(options.locale);
|
|
377
|
+
} else {
|
|
378
|
+
memo = getHolidayDescription(e);
|
|
380
379
|
}
|
|
381
|
-
|
|
382
|
-
|
|
380
|
+
}
|
|
381
|
+
if (torahMemo) {
|
|
382
|
+
if (memo.length) {
|
|
383
|
+
memo += '\\n\\n';
|
|
383
384
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
memo +=
|
|
385
|
+
memo += torahMemo;
|
|
386
|
+
}
|
|
387
|
+
if (url) {
|
|
388
|
+
if (memo.length) {
|
|
389
|
+
memo += '\\n\\n';
|
|
389
390
|
}
|
|
390
|
-
|
|
391
|
+
memo += url;
|
|
391
392
|
}
|
|
393
|
+
return memo;
|
|
392
394
|
}
|
|
393
395
|
|
|
394
396
|
/**
|
|
395
397
|
* Generates an RFC 2445 iCalendar string from an array of events
|
|
396
398
|
* @param {Event[]} events
|
|
397
|
-
* @param {
|
|
399
|
+
* @param {CalOptions} options
|
|
398
400
|
* @return {Promise<string>}
|
|
399
401
|
*/
|
|
400
402
|
async function eventsToIcalendar(events, options) {
|
|
@@ -412,7 +414,7 @@ async function eventsToIcalendar(events, options) {
|
|
|
412
414
|
/**
|
|
413
415
|
* Generates an RFC 2445 iCalendar string from an array of IcalEvents
|
|
414
416
|
* @param {IcalEvent[]} icals
|
|
415
|
-
* @param {
|
|
417
|
+
* @param {CalOptions} options
|
|
416
418
|
* @return {Promise<string>}
|
|
417
419
|
*/
|
|
418
420
|
async function icalEventsToString(icals, options) {
|
|
@@ -442,8 +444,8 @@ async function icalEventsToString(icals, options) {
|
|
|
442
444
|
stream.push(`X-APPLE-CALENDAR-COLOR:${opts.calendarColor}\r\n`);
|
|
443
445
|
}
|
|
444
446
|
const location = opts.location;
|
|
445
|
-
|
|
446
|
-
|
|
447
|
+
const tzid = location?.getTzid();
|
|
448
|
+
if (tzid) {
|
|
447
449
|
stream.push(`X-WR-TIMEZONE;VALUE=TEXT:${tzid}\r\n`);
|
|
448
450
|
if (VTIMEZONE[tzid]) {
|
|
449
451
|
stream.push(VTIMEZONE[tzid]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hebcal/icalendar",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"author": "Michael J. Radwin (https://github.com/mjradwin)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ical",
|
|
@@ -11,10 +11,6 @@
|
|
|
11
11
|
"description": "Jewish holidays and Hebrew calendar as iCalendar RFC 2445",
|
|
12
12
|
"main": "dist/index.js",
|
|
13
13
|
"module": "dist/index.mjs",
|
|
14
|
-
"exports": {
|
|
15
|
-
"import": "./dist/index.mjs",
|
|
16
|
-
"require": "./dist/index.js"
|
|
17
|
-
},
|
|
18
14
|
"typings": "icalendar.d.ts",
|
|
19
15
|
"files": [
|
|
20
16
|
"dist",
|
|
@@ -28,8 +24,8 @@
|
|
|
28
24
|
"url": "https://github.com/hebcal/hebcal-icalendar/issues"
|
|
29
25
|
},
|
|
30
26
|
"dependencies": {
|
|
31
|
-
"@hebcal/core": "^
|
|
32
|
-
"@hebcal/rest-api": "^
|
|
27
|
+
"@hebcal/core": "^5.0.0-rc2",
|
|
28
|
+
"@hebcal/rest-api": "^5.0.0",
|
|
33
29
|
"murmurhash3": "^0.5.0"
|
|
34
30
|
},
|
|
35
31
|
"scripts": {
|
|
@@ -46,18 +42,18 @@
|
|
|
46
42
|
]
|
|
47
43
|
},
|
|
48
44
|
"devDependencies": {
|
|
49
|
-
"@babel/core": "^7.
|
|
50
|
-
"@babel/preset-env": "^7.
|
|
51
|
-
"@babel/register": "^7.22.
|
|
52
|
-
"@hebcal/learning": "^
|
|
53
|
-
"@rollup/plugin-babel": "^6.0.
|
|
54
|
-
"@rollup/plugin-commonjs": "^25.0.
|
|
55
|
-
"@rollup/plugin-json": "^6.0.
|
|
45
|
+
"@babel/core": "^7.23.3",
|
|
46
|
+
"@babel/preset-env": "^7.23.3",
|
|
47
|
+
"@babel/register": "^7.22.15",
|
|
48
|
+
"@hebcal/learning": "^5.0.0",
|
|
49
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
50
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
51
|
+
"@rollup/plugin-json": "^6.0.1",
|
|
56
52
|
"ava": "^5.3.1",
|
|
57
|
-
"eslint": "^8.
|
|
53
|
+
"eslint": "^8.54.0",
|
|
58
54
|
"eslint-config-google": "^0.14.0",
|
|
59
55
|
"jsdoc": "^4.0.2",
|
|
60
56
|
"jsdoc-to-markdown": "^8.0.0",
|
|
61
|
-
"rollup": "^
|
|
57
|
+
"rollup": "^4.5.1"
|
|
62
58
|
}
|
|
63
59
|
}
|