@hebcal/icalendar 4.20.1 → 4.22.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 -31
- package/dist/index.mjs +41 -31
- package/package.json +12 -16
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @hebcal/icalendar v4.
|
|
1
|
+
/*! @hebcal/icalendar v4.22.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="4.
|
|
9
|
+
const version="4.22.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,12 +65,17 @@ 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;
|
|
72
72
|
this.options = options;
|
|
73
73
|
this.dtstamp = options.dtstamp || IcalEvent.makeDtstamp(new Date());
|
|
74
|
+
if (typeof ev.sequence === 'number') {
|
|
75
|
+
this.sequence = ev.sequence;
|
|
76
|
+
} else if (typeof options.sequence === 'number') {
|
|
77
|
+
this.sequence = options.sequence;
|
|
78
|
+
}
|
|
74
79
|
const timed = this.timed = Boolean(ev.eventTime);
|
|
75
80
|
const locale = options.locale;
|
|
76
81
|
let subj = restApi.shouldRenderBrief(ev) ? ev.renderBrief(locale) : ev.render(locale);
|
|
@@ -85,7 +90,7 @@ class IcalEvent {
|
|
|
85
90
|
this.locationName = core.Locale.gettext('Nach Yomi');
|
|
86
91
|
} else if (mask & core.flags.MISHNA_YOMI) {
|
|
87
92
|
this.locationName = core.Locale.gettext('Mishna Yomi');
|
|
88
|
-
} else if (timed && options.location
|
|
93
|
+
} else if (timed && options.location?.name) {
|
|
89
94
|
const comma = options.location.name.indexOf(',');
|
|
90
95
|
this.locationName = comma == -1 ? options.location.name : options.location.name.substring(0, comma);
|
|
91
96
|
}
|
|
@@ -100,7 +105,7 @@ class IcalEvent {
|
|
|
100
105
|
minute = +minute;
|
|
101
106
|
this.startDate += 'T' + restApi.pad2(hour) + restApi.pad2(minute) + '00';
|
|
102
107
|
this.endDate = this.startDate;
|
|
103
|
-
if (options.location
|
|
108
|
+
if (options.location?.tzid) {
|
|
104
109
|
this.dtargs = `;TZID=${options.location.tzid}`;
|
|
105
110
|
}
|
|
106
111
|
} else {
|
|
@@ -183,8 +188,11 @@ class IcalEvent {
|
|
|
183
188
|
*/
|
|
184
189
|
getLongLines() {
|
|
185
190
|
if (this.lines) return this.lines;
|
|
186
|
-
const categoryLine = this.category ? `CATEGORIES:${this.category}` : [];
|
|
191
|
+
const categoryLine = this.category ? [`CATEGORIES:${this.category}`] : [];
|
|
187
192
|
const uid = this.ev.uid || this.getUid();
|
|
193
|
+
if (this.sequence) {
|
|
194
|
+
categoryLine.unshift(`SEQUENCE:${this.sequence}`);
|
|
195
|
+
}
|
|
188
196
|
const arr = this.lines = ['BEGIN:VEVENT', `DTSTAMP:${this.dtstamp}`].concat(categoryLine).concat([`SUMMARY:${this.subj}`, `DTSTART${this.dtargs}:${this.startDate}`, `DTEND${this.dtargs}:${this.endDate}`, `UID:${uid}`, `TRANSP:${this.transp}`, `X-MICROSOFT-CDO-BUSYSTATUS:${this.busyStatus}`]);
|
|
189
197
|
if (!this.timed) {
|
|
190
198
|
arr.push('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE');
|
|
@@ -309,7 +317,7 @@ class IcalEvent {
|
|
|
309
317
|
/**
|
|
310
318
|
* Transforms a single Event into a VEVENT string
|
|
311
319
|
* @param {Event} ev
|
|
312
|
-
* @param {
|
|
320
|
+
* @param {CalOptions} options
|
|
313
321
|
* @return {string} multi-line result, delimited by \r\n
|
|
314
322
|
*/
|
|
315
323
|
function eventToIcal(ev, options) {
|
|
@@ -346,17 +354,17 @@ function makeTorahMemo(ev, il) {
|
|
|
346
354
|
/**
|
|
347
355
|
* @private
|
|
348
356
|
* @param {Event} e
|
|
349
|
-
* @param {
|
|
357
|
+
* @param {CalOptions} options
|
|
350
358
|
* @return {string}
|
|
351
359
|
*/
|
|
352
360
|
function createMemo(e, options) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
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');
|
|
357
364
|
}
|
|
358
|
-
|
|
359
|
-
|
|
365
|
+
const desc = e.getDesc();
|
|
366
|
+
if (desc === 'Havdalah' || desc === 'Candle lighting') {
|
|
367
|
+
return memo || '';
|
|
360
368
|
}
|
|
361
369
|
const mask = e.getFlags();
|
|
362
370
|
if (mask & core.flags.OMER_COUNT) {
|
|
@@ -365,30 +373,32 @@ function createMemo(e, options) {
|
|
|
365
373
|
}
|
|
366
374
|
const url = appendTrackingToUrl(e.url(), options);
|
|
367
375
|
const torahMemo = makeTorahMemo(e, options.il);
|
|
368
|
-
if (
|
|
369
|
-
|
|
370
|
-
} else {
|
|
371
|
-
let memo = e.memo || restApi.getHolidayDescription(e);
|
|
372
|
-
if (!memo && typeof e.linkedEvent !== 'undefined') {
|
|
376
|
+
if (!memo) {
|
|
377
|
+
if (typeof e.linkedEvent !== 'undefined') {
|
|
373
378
|
memo = e.linkedEvent.render(options.locale);
|
|
379
|
+
} else {
|
|
380
|
+
memo = restApi.getHolidayDescription(e);
|
|
374
381
|
}
|
|
375
|
-
|
|
376
|
-
|
|
382
|
+
}
|
|
383
|
+
if (torahMemo) {
|
|
384
|
+
if (memo.length) {
|
|
385
|
+
memo += '\\n\\n';
|
|
377
386
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
memo +=
|
|
387
|
+
memo += torahMemo;
|
|
388
|
+
}
|
|
389
|
+
if (url) {
|
|
390
|
+
if (memo.length) {
|
|
391
|
+
memo += '\\n\\n';
|
|
383
392
|
}
|
|
384
|
-
|
|
393
|
+
memo += url;
|
|
385
394
|
}
|
|
395
|
+
return memo;
|
|
386
396
|
}
|
|
387
397
|
|
|
388
398
|
/**
|
|
389
399
|
* Generates an RFC 2445 iCalendar string from an array of events
|
|
390
400
|
* @param {Event[]} events
|
|
391
|
-
* @param {
|
|
401
|
+
* @param {CalOptions} options
|
|
392
402
|
* @return {Promise<string>}
|
|
393
403
|
*/
|
|
394
404
|
async function eventsToIcalendar(events, options) {
|
|
@@ -406,7 +416,7 @@ async function eventsToIcalendar(events, options) {
|
|
|
406
416
|
/**
|
|
407
417
|
* Generates an RFC 2445 iCalendar string from an array of IcalEvents
|
|
408
418
|
* @param {IcalEvent[]} icals
|
|
409
|
-
* @param {
|
|
419
|
+
* @param {CalOptions} options
|
|
410
420
|
* @return {Promise<string>}
|
|
411
421
|
*/
|
|
412
422
|
async function icalEventsToString(icals, options) {
|
|
@@ -436,7 +446,7 @@ async function icalEventsToString(icals, options) {
|
|
|
436
446
|
stream.push(`X-APPLE-CALENDAR-COLOR:${opts.calendarColor}\r\n`);
|
|
437
447
|
}
|
|
438
448
|
const location = opts.location;
|
|
439
|
-
if (location
|
|
449
|
+
if (location?.tzid) {
|
|
440
450
|
const tzid = location.tzid;
|
|
441
451
|
stream.push(`X-WR-TIMEZONE;VALUE=TEXT:${tzid}\r\n`);
|
|
442
452
|
if (VTIMEZONE[tzid]) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/*! @hebcal/icalendar v4.
|
|
1
|
+
/*! @hebcal/icalendar v4.22.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="4.
|
|
7
|
+
const version="4.22.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,12 +63,17 @@ 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;
|
|
70
70
|
this.options = options;
|
|
71
71
|
this.dtstamp = options.dtstamp || IcalEvent.makeDtstamp(new Date());
|
|
72
|
+
if (typeof ev.sequence === 'number') {
|
|
73
|
+
this.sequence = ev.sequence;
|
|
74
|
+
} else if (typeof options.sequence === 'number') {
|
|
75
|
+
this.sequence = options.sequence;
|
|
76
|
+
}
|
|
72
77
|
const timed = this.timed = Boolean(ev.eventTime);
|
|
73
78
|
const locale = options.locale;
|
|
74
79
|
let subj = shouldRenderBrief(ev) ? ev.renderBrief(locale) : ev.render(locale);
|
|
@@ -83,7 +88,7 @@ class IcalEvent {
|
|
|
83
88
|
this.locationName = Locale.gettext('Nach Yomi');
|
|
84
89
|
} else if (mask & flags.MISHNA_YOMI) {
|
|
85
90
|
this.locationName = Locale.gettext('Mishna Yomi');
|
|
86
|
-
} else if (timed && options.location
|
|
91
|
+
} else if (timed && options.location?.name) {
|
|
87
92
|
const comma = options.location.name.indexOf(',');
|
|
88
93
|
this.locationName = comma == -1 ? options.location.name : options.location.name.substring(0, comma);
|
|
89
94
|
}
|
|
@@ -98,7 +103,7 @@ class IcalEvent {
|
|
|
98
103
|
minute = +minute;
|
|
99
104
|
this.startDate += 'T' + pad2(hour) + pad2(minute) + '00';
|
|
100
105
|
this.endDate = this.startDate;
|
|
101
|
-
if (options.location
|
|
106
|
+
if (options.location?.tzid) {
|
|
102
107
|
this.dtargs = `;TZID=${options.location.tzid}`;
|
|
103
108
|
}
|
|
104
109
|
} else {
|
|
@@ -181,8 +186,11 @@ class IcalEvent {
|
|
|
181
186
|
*/
|
|
182
187
|
getLongLines() {
|
|
183
188
|
if (this.lines) return this.lines;
|
|
184
|
-
const categoryLine = this.category ? `CATEGORIES:${this.category}` : [];
|
|
189
|
+
const categoryLine = this.category ? [`CATEGORIES:${this.category}`] : [];
|
|
185
190
|
const uid = this.ev.uid || this.getUid();
|
|
191
|
+
if (this.sequence) {
|
|
192
|
+
categoryLine.unshift(`SEQUENCE:${this.sequence}`);
|
|
193
|
+
}
|
|
186
194
|
const arr = this.lines = ['BEGIN:VEVENT', `DTSTAMP:${this.dtstamp}`].concat(categoryLine).concat([`SUMMARY:${this.subj}`, `DTSTART${this.dtargs}:${this.startDate}`, `DTEND${this.dtargs}:${this.endDate}`, `UID:${uid}`, `TRANSP:${this.transp}`, `X-MICROSOFT-CDO-BUSYSTATUS:${this.busyStatus}`]);
|
|
187
195
|
if (!this.timed) {
|
|
188
196
|
arr.push('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE');
|
|
@@ -307,7 +315,7 @@ class IcalEvent {
|
|
|
307
315
|
/**
|
|
308
316
|
* Transforms a single Event into a VEVENT string
|
|
309
317
|
* @param {Event} ev
|
|
310
|
-
* @param {
|
|
318
|
+
* @param {CalOptions} options
|
|
311
319
|
* @return {string} multi-line result, delimited by \r\n
|
|
312
320
|
*/
|
|
313
321
|
function eventToIcal(ev, options) {
|
|
@@ -344,17 +352,17 @@ function makeTorahMemo(ev, il) {
|
|
|
344
352
|
/**
|
|
345
353
|
* @private
|
|
346
354
|
* @param {Event} e
|
|
347
|
-
* @param {
|
|
355
|
+
* @param {CalOptions} options
|
|
348
356
|
* @return {string}
|
|
349
357
|
*/
|
|
350
358
|
function createMemo(e, options) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
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');
|
|
355
362
|
}
|
|
356
|
-
|
|
357
|
-
|
|
363
|
+
const desc = e.getDesc();
|
|
364
|
+
if (desc === 'Havdalah' || desc === 'Candle lighting') {
|
|
365
|
+
return memo || '';
|
|
358
366
|
}
|
|
359
367
|
const mask = e.getFlags();
|
|
360
368
|
if (mask & flags.OMER_COUNT) {
|
|
@@ -363,30 +371,32 @@ function createMemo(e, options) {
|
|
|
363
371
|
}
|
|
364
372
|
const url = appendTrackingToUrl(e.url(), options);
|
|
365
373
|
const torahMemo = makeTorahMemo(e, options.il);
|
|
366
|
-
if (
|
|
367
|
-
|
|
368
|
-
} else {
|
|
369
|
-
let memo = e.memo || getHolidayDescription(e);
|
|
370
|
-
if (!memo && typeof e.linkedEvent !== 'undefined') {
|
|
374
|
+
if (!memo) {
|
|
375
|
+
if (typeof e.linkedEvent !== 'undefined') {
|
|
371
376
|
memo = e.linkedEvent.render(options.locale);
|
|
377
|
+
} else {
|
|
378
|
+
memo = getHolidayDescription(e);
|
|
372
379
|
}
|
|
373
|
-
|
|
374
|
-
|
|
380
|
+
}
|
|
381
|
+
if (torahMemo) {
|
|
382
|
+
if (memo.length) {
|
|
383
|
+
memo += '\\n\\n';
|
|
375
384
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
memo +=
|
|
385
|
+
memo += torahMemo;
|
|
386
|
+
}
|
|
387
|
+
if (url) {
|
|
388
|
+
if (memo.length) {
|
|
389
|
+
memo += '\\n\\n';
|
|
381
390
|
}
|
|
382
|
-
|
|
391
|
+
memo += url;
|
|
383
392
|
}
|
|
393
|
+
return memo;
|
|
384
394
|
}
|
|
385
395
|
|
|
386
396
|
/**
|
|
387
397
|
* Generates an RFC 2445 iCalendar string from an array of events
|
|
388
398
|
* @param {Event[]} events
|
|
389
|
-
* @param {
|
|
399
|
+
* @param {CalOptions} options
|
|
390
400
|
* @return {Promise<string>}
|
|
391
401
|
*/
|
|
392
402
|
async function eventsToIcalendar(events, options) {
|
|
@@ -404,7 +414,7 @@ async function eventsToIcalendar(events, options) {
|
|
|
404
414
|
/**
|
|
405
415
|
* Generates an RFC 2445 iCalendar string from an array of IcalEvents
|
|
406
416
|
* @param {IcalEvent[]} icals
|
|
407
|
-
* @param {
|
|
417
|
+
* @param {CalOptions} options
|
|
408
418
|
* @return {Promise<string>}
|
|
409
419
|
*/
|
|
410
420
|
async function icalEventsToString(icals, options) {
|
|
@@ -434,7 +444,7 @@ async function icalEventsToString(icals, options) {
|
|
|
434
444
|
stream.push(`X-APPLE-CALENDAR-COLOR:${opts.calendarColor}\r\n`);
|
|
435
445
|
}
|
|
436
446
|
const location = opts.location;
|
|
437
|
-
if (location
|
|
447
|
+
if (location?.tzid) {
|
|
438
448
|
const tzid = location.tzid;
|
|
439
449
|
stream.push(`X-WR-TIMEZONE;VALUE=TEXT:${tzid}\r\n`);
|
|
440
450
|
if (VTIMEZONE[tzid]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hebcal/icalendar",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.22.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": "^4.
|
|
32
|
-
"@hebcal/rest-api": "^4.5.
|
|
27
|
+
"@hebcal/core": "^4.4.1",
|
|
28
|
+
"@hebcal/rest-api": "^4.5.7",
|
|
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": "^1.
|
|
53
|
-
"@rollup/plugin-babel": "^6.0.
|
|
54
|
-
"@rollup/plugin-commonjs": "^25.0.
|
|
55
|
-
"@rollup/plugin-json": "^6.0.
|
|
45
|
+
"@babel/core": "^7.23.2",
|
|
46
|
+
"@babel/preset-env": "^7.23.2",
|
|
47
|
+
"@babel/register": "^7.22.15",
|
|
48
|
+
"@hebcal/learning": "^1.5.2",
|
|
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.51.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.1.4"
|
|
62
58
|
}
|
|
63
59
|
}
|