@hebcal/icalendar 4.15.3 → 4.17.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.
Files changed (3) hide show
  1. package/dist/index.js +32 -35
  2. package/dist/index.mjs +33 -36
  3. package/package.json +10 -10
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/icalendar v4.15.3 */
1
+ /*! @hebcal/icalendar v4.17.0 */
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -8,7 +8,7 @@ var murmurhash3 = require('murmurhash3');
8
8
  var restApi = require('@hebcal/rest-api');
9
9
  var fs = require('fs');
10
10
 
11
- var version="4.15.3";
11
+ const version="4.17.0";
12
12
 
13
13
  const VTIMEZONE = {};
14
14
  const CATEGORY = {
@@ -55,28 +55,6 @@ function appendTrackingToUrl(url, options) {
55
55
  const utmSource = options.utmSource || 'js';
56
56
  const utmMedium = options.utmMedium || 'icalendar';
57
57
  const utmCampaign = options.utmCampaign;
58
- const u = new URL(url);
59
-
60
- if (utmCampaign && utmCampaign.startsWith('ical-') && u.host === 'www.hebcal.com') {
61
- u.host = 'hebcal.com';
62
- const path = u.pathname;
63
-
64
- if (path.startsWith('/holidays/')) {
65
- u.pathname = '/h/' + path.substring(10);
66
- } else if (path.startsWith('/sedrot/')) {
67
- u.pathname = '/s/' + path.substring(8);
68
- } else {
69
- return restApi.appendIsraelAndTracking(url, options.il, utmSource, utmMedium, utmCampaign);
70
- }
71
-
72
- if (options.il) {
73
- u.searchParams.set('i', 'on');
74
- }
75
-
76
- u.searchParams.set('uc', utmCampaign);
77
- return u.toString();
78
- }
79
-
80
58
  return restApi.appendIsraelAndTracking(url, options.il, utmSource, utmMedium, utmCampaign);
81
59
  }
82
60
 
@@ -161,19 +139,32 @@ class IcalEvent {
161
139
  }
162
140
 
163
141
  this.subj = subj;
164
- const isUserEvent = Boolean(mask & core.flags.USER_EVENT);
142
+ this.category = ev.category || CATEGORY[restApi.getEventCategories(ev)[0]];
143
+ }
144
+ /**
145
+ * @return {string}
146
+ */
147
+
148
+
149
+ getAlarm() {
150
+ const ev = this.ev;
151
+ const mask = ev.getFlags();
152
+ const evAlarm = ev.alarm;
165
153
 
166
- if (ev.alarm) {
167
- this.alarm = ev.alarm;
154
+ if (typeof evAlarm === 'string') {
155
+ return 'TRIGGER:' + evAlarm;
156
+ } else if (core.greg.isDate(evAlarm)) {
157
+ evAlarm.setSeconds(0);
158
+ return 'TRIGGER;VALUE=DATE-TIME:' + IcalEvent.makeDtstamp(evAlarm);
168
159
  } else if (mask & core.flags.OMER_COUNT) {
169
- this.alarm = '-P0DT3H30M0S'; // 8:30pm Omer alarm evening before
170
- } else if (isUserEvent) {
171
- this.alarm = '-P0DT12H0M0S'; // noon the day before
172
- } else if (timed && ev.getDesc().startsWith('Candle lighting')) {
173
- this.alarm = '-P0DT0H10M0S'; // ten minutes
160
+ return 'TRIGGER:-P0DT3H30M0S'; // 8:30pm Omer alarm evening before
161
+ } else if (mask & core.flags.USER_EVENT) {
162
+ return 'TRIGGER:-P0DT12H0M0S'; // noon the day before
163
+ } else if (this.timed && ev.getDesc().startsWith('Candle lighting')) {
164
+ return 'TRIGGER:-P0DT0H10M0S';
174
165
  }
175
166
 
176
- this.category = ev.category || CATEGORY[restApi.getEventCategories(ev)[0]];
167
+ return null;
177
168
  }
178
169
  /**
179
170
  * @return {string}
@@ -228,8 +219,10 @@ class IcalEvent {
228
219
  arr.push('GEO:' + options.location.latitude + ';' + options.location.longitude);
229
220
  }
230
221
 
231
- if (this.alarm) {
232
- arr.push('BEGIN:VALARM', 'ACTION:DISPLAY', 'DESCRIPTION:This is an event reminder', `TRIGGER:${this.alarm}`, 'END:VALARM');
222
+ const trigger = this.getAlarm();
223
+
224
+ if (trigger) {
225
+ arr.push('BEGIN:VALARM', 'ACTION:DISPLAY', 'DESCRIPTION:Event reminder', `${trigger}`, 'END:VALARM');
233
226
  }
234
227
 
235
228
  arr.push('END:VEVENT');
@@ -399,6 +392,10 @@ function createMemo(e, options) {
399
392
  const desc = e.getDesc();
400
393
  const candles = desc === 'Havdalah' || desc === 'Candle lighting';
401
394
 
395
+ if (typeof e.memo === 'string' && e.memo.length && e.memo.indexOf('\n') !== -1) {
396
+ e.memo = e.memo.replace(/\n/g, '\\n');
397
+ }
398
+
402
399
  if (candles) {
403
400
  return e.memo || '';
404
401
  }
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- /*! @hebcal/icalendar v4.15.3 */
2
- import { flags, Locale } from '@hebcal/core';
1
+ /*! @hebcal/icalendar v4.17.0 */
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
- var version="4.15.3";
7
+ const version="4.17.0";
8
8
 
9
9
  const VTIMEZONE = {};
10
10
  const CATEGORY = {
@@ -51,28 +51,6 @@ function appendTrackingToUrl(url, options) {
51
51
  const utmSource = options.utmSource || 'js';
52
52
  const utmMedium = options.utmMedium || 'icalendar';
53
53
  const utmCampaign = options.utmCampaign;
54
- const u = new URL(url);
55
-
56
- if (utmCampaign && utmCampaign.startsWith('ical-') && u.host === 'www.hebcal.com') {
57
- u.host = 'hebcal.com';
58
- const path = u.pathname;
59
-
60
- if (path.startsWith('/holidays/')) {
61
- u.pathname = '/h/' + path.substring(10);
62
- } else if (path.startsWith('/sedrot/')) {
63
- u.pathname = '/s/' + path.substring(8);
64
- } else {
65
- return appendIsraelAndTracking(url, options.il, utmSource, utmMedium, utmCampaign);
66
- }
67
-
68
- if (options.il) {
69
- u.searchParams.set('i', 'on');
70
- }
71
-
72
- u.searchParams.set('uc', utmCampaign);
73
- return u.toString();
74
- }
75
-
76
54
  return appendIsraelAndTracking(url, options.il, utmSource, utmMedium, utmCampaign);
77
55
  }
78
56
 
@@ -157,19 +135,32 @@ class IcalEvent {
157
135
  }
158
136
 
159
137
  this.subj = subj;
160
- const isUserEvent = Boolean(mask & flags.USER_EVENT);
138
+ this.category = ev.category || CATEGORY[getEventCategories(ev)[0]];
139
+ }
140
+ /**
141
+ * @return {string}
142
+ */
143
+
144
+
145
+ getAlarm() {
146
+ const ev = this.ev;
147
+ const mask = ev.getFlags();
148
+ const evAlarm = ev.alarm;
161
149
 
162
- if (ev.alarm) {
163
- this.alarm = ev.alarm;
150
+ if (typeof evAlarm === 'string') {
151
+ return 'TRIGGER:' + evAlarm;
152
+ } else if (greg.isDate(evAlarm)) {
153
+ evAlarm.setSeconds(0);
154
+ return 'TRIGGER;VALUE=DATE-TIME:' + IcalEvent.makeDtstamp(evAlarm);
164
155
  } else if (mask & flags.OMER_COUNT) {
165
- this.alarm = '-P0DT3H30M0S'; // 8:30pm Omer alarm evening before
166
- } else if (isUserEvent) {
167
- this.alarm = '-P0DT12H0M0S'; // noon the day before
168
- } else if (timed && ev.getDesc().startsWith('Candle lighting')) {
169
- this.alarm = '-P0DT0H10M0S'; // ten minutes
156
+ return 'TRIGGER:-P0DT3H30M0S'; // 8:30pm Omer alarm evening before
157
+ } else if (mask & flags.USER_EVENT) {
158
+ return 'TRIGGER:-P0DT12H0M0S'; // noon the day before
159
+ } else if (this.timed && ev.getDesc().startsWith('Candle lighting')) {
160
+ return 'TRIGGER:-P0DT0H10M0S';
170
161
  }
171
162
 
172
- this.category = ev.category || CATEGORY[getEventCategories(ev)[0]];
163
+ return null;
173
164
  }
174
165
  /**
175
166
  * @return {string}
@@ -224,8 +215,10 @@ class IcalEvent {
224
215
  arr.push('GEO:' + options.location.latitude + ';' + options.location.longitude);
225
216
  }
226
217
 
227
- if (this.alarm) {
228
- arr.push('BEGIN:VALARM', 'ACTION:DISPLAY', 'DESCRIPTION:This is an event reminder', `TRIGGER:${this.alarm}`, 'END:VALARM');
218
+ const trigger = this.getAlarm();
219
+
220
+ if (trigger) {
221
+ arr.push('BEGIN:VALARM', 'ACTION:DISPLAY', 'DESCRIPTION:Event reminder', `${trigger}`, 'END:VALARM');
229
222
  }
230
223
 
231
224
  arr.push('END:VEVENT');
@@ -395,6 +388,10 @@ function createMemo(e, options) {
395
388
  const desc = e.getDesc();
396
389
  const candles = desc === 'Havdalah' || desc === 'Candle lighting';
397
390
 
391
+ if (typeof e.memo === 'string' && e.memo.length && e.memo.indexOf('\n') !== -1) {
392
+ e.memo = e.memo.replace(/\n/g, '\\n');
393
+ }
394
+
398
395
  if (candles) {
399
396
  return e.memo || '';
400
397
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hebcal/icalendar",
3
- "version": "4.15.3",
3
+ "version": "4.17.0",
4
4
  "author": "Michael J. Radwin (https://github.com/mjradwin)",
5
5
  "keywords": [
6
6
  "ical",
@@ -24,8 +24,8 @@
24
24
  "url": "https://github.com/hebcal/hebcal-icalendar/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@hebcal/core": "^3.33.3",
28
- "@hebcal/rest-api": "^3.12.0",
27
+ "@hebcal/core": "^3.36.0",
28
+ "@hebcal/rest-api": "^3.13.0",
29
29
  "murmurhash3": "^0.5.0"
30
30
  },
31
31
  "scripts": {
@@ -48,18 +48,18 @@
48
48
  "verbose": true
49
49
  },
50
50
  "devDependencies": {
51
- "@babel/core": "^7.17.5",
51
+ "@babel/core": "^7.17.9",
52
52
  "@babel/preset-env": "^7.16.11",
53
- "@babel/register": "^7.17.0",
53
+ "@babel/register": "^7.17.7",
54
54
  "@rollup/plugin-babel": "^5.3.1",
55
- "@rollup/plugin-commonjs": "^21.0.2",
55
+ "@rollup/plugin-commonjs": "^22.0.0",
56
56
  "@rollup/plugin-json": "^4.1.0",
57
- "@rollup/plugin-node-resolve": "^13.1.3",
58
- "ava": "^4.0.1",
59
- "eslint": "^8.10.0",
57
+ "@rollup/plugin-node-resolve": "^13.2.1",
58
+ "ava": "^4.2.0",
59
+ "eslint": "^8.14.0",
60
60
  "eslint-config-google": "^0.14.0",
61
61
  "jsdoc": "^3.6.10",
62
62
  "jsdoc-to-markdown": "^7.1.1",
63
- "rollup": "^2.68.0"
63
+ "rollup": "^2.70.2"
64
64
  }
65
65
  }