@hebcal/icalendar
Advanced tools
Comparing version 4.2.0 to 4.3.0
@@ -1,2 +0,2 @@ | ||
/*! @hebcal/icalendar v4.2.0 */ | ||
/*! @hebcal/icalendar v4.3.0 */ | ||
'use strict'; | ||
@@ -402,3 +402,3 @@ | ||
var version="4.2.0"; | ||
var version="4.3.0"; | ||
@@ -422,23 +422,2 @@ const VTIMEZONE = {}; | ||
* @private | ||
* @param {Date} d | ||
* @return {string} | ||
*/ | ||
function formatYYYYMMDD(d) { | ||
return pad4(d.getFullYear()) + pad2(d.getMonth() + 1) + pad2(d.getDate()); | ||
} | ||
/** | ||
* Returns UTC string for iCalendar | ||
* @private | ||
* @param {Date} dt | ||
* @return {string} | ||
*/ | ||
function makeDtstamp(dt) { | ||
const s = dt.toISOString(); | ||
return s.slice(0, 4) + s.slice(5, 7) + s.slice(8, 13) + s.slice(14, 16) + s.slice(17, 19) + 'Z'; | ||
} | ||
/** | ||
* @private | ||
* @param {string[]} arr | ||
@@ -449,6 +428,5 @@ * @param {string} key | ||
function addOptional(arr, key, val) { | ||
if (val) { | ||
const str = icalEscapeStr(val); | ||
const str = IcalEvent.escape(val); | ||
arr.push(key + ':' + str); | ||
@@ -459,12 +437,2 @@ } | ||
* @private | ||
* @param {string} str | ||
* @return {string} | ||
*/ | ||
function icalEscapeStr(str) { | ||
return str.replace(/,/g, '\\,').replace(/;/g, '\\;'); | ||
} | ||
/** | ||
* @private | ||
* @param {string} url | ||
@@ -499,4 +467,4 @@ * @param {boolean} il | ||
*/ | ||
constructor(ev, options) { | ||
const dtstamp = options.dtstamp || makeDtstamp(new Date()); | ||
constructor(ev, options = {}) { | ||
const dtstamp = options.dtstamp || IcalEvent.makeDtstamp(new Date()); | ||
const timed = Boolean(ev.eventTime); | ||
@@ -509,3 +477,3 @@ let subj = timed || ev.getFlags() & core.flags.DAF_YOMI ? ev.renderBrief() : ev.render(); | ||
if (timed && options.location.name) { | ||
if (timed && options.location && options.location.name) { | ||
const comma = options.location.name.indexOf(','); | ||
@@ -519,5 +487,5 @@ location = comma == -1 ? options.location.name : options.location.name.substring(0, comma); | ||
const date = formatYYYYMMDD(ev.getDate().greg()); | ||
const date = IcalEvent.formatYYYYMMDD(ev.getDate().greg()); | ||
let startDate = date; | ||
let dtargs; | ||
let dtargs = ''; | ||
let endDate; | ||
@@ -533,5 +501,8 @@ let transp = 'TRANSPARENT'; | ||
endDate = startDate; | ||
dtargs = `;TZID=${options.location.tzid}`; | ||
if (options.location && options.location.tzid) { | ||
dtargs = `;TZID=${options.location.tzid}`; | ||
} | ||
} else { | ||
endDate = formatYYYYMMDD(ev.getDate().next().greg()); // for all-day untimed, use DTEND;VALUE=DATE intsead of DURATION:P1D. | ||
endDate = IcalEvent.formatYYYYMMDD(ev.getDate().next().greg()); // for all-day untimed, use DTEND;VALUE=DATE intsead of DURATION:P1D. | ||
// It's more compatible with everthing except ancient versions of | ||
@@ -560,3 +531,3 @@ // Lotus Notes circa 2004 | ||
subj = subj.replace(/,/g, '\\,'); | ||
subj = IcalEvent.escape(subj); | ||
@@ -636,3 +607,46 @@ if (options.appendHebrewToSubject) { | ||
} | ||
/** | ||
* @param {string} str | ||
* @return {string} | ||
*/ | ||
static escape(str) { | ||
if (str.indexOf(',') !== -1) { | ||
str = str.replace(/,/g, '\\,'); | ||
} | ||
if (str.indexOf(';') !== -1) { | ||
str = str.replace(/;/g, '\\;'); | ||
} | ||
return str; | ||
} | ||
/** | ||
* @param {Date} dt | ||
* @return {string} | ||
*/ | ||
static formatYYYYMMDD(dt) { | ||
return pad4(dt.getFullYear()) + pad2(dt.getMonth() + 1) + pad2(dt.getDate()); | ||
} | ||
/** | ||
* Returns UTC string for iCalendar | ||
* @param {Date} dt | ||
* @return {string} | ||
*/ | ||
static makeDtstamp(dt) { | ||
const s = dt.toISOString(); | ||
return s.slice(0, 4) + s.slice(5, 7) + s.slice(8, 13) + s.slice(14, 16) + s.slice(17, 19) + 'Z'; | ||
} | ||
/** @return {string} */ | ||
static version() { | ||
return version; | ||
} | ||
} | ||
@@ -698,3 +712,3 @@ /** | ||
const uclang = core.Locale.getLocaleName().toUpperCase(); | ||
const title = options.title ? icalEscapeStr(options.title) : getCalendarTitle(events, options); | ||
const title = options.title ? IcalEvent.escape(options.title) : getCalendarTitle(events, options); | ||
const caldesc = options.yahrzeit ? 'Yahrzeits + Anniversaries from www.hebcal.com' : 'Jewish Holidays from www.hebcal.com'; | ||
@@ -737,3 +751,3 @@ const preamble = ['BEGIN:VCALENDAR', 'VERSION:2.0', `PRODID:-//hebcal.com/NONSGML Hebcal Calendar v1${version}//${uclang}`, 'CALSCALE:GREGORIAN', 'METHOD:PUBLISH', 'X-LOTUS-CHARSET:UTF-8', 'X-PUBLISHED-TTL:PT7D', `X-WR-CALNAME:${title}`, `X-WR-CALDESC:${caldesc}`]; | ||
options.dtstamp = makeDtstamp(new Date()); | ||
options.dtstamp = IcalEvent.makeDtstamp(new Date()); | ||
@@ -740,0 +754,0 @@ for (const ev of events) { |
@@ -25,3 +25,7 @@ /// <reference types="node"/> | ||
getLongLines(): string[]; | ||
static escape(str: string): string; | ||
static formatYYYYMMDD(dt: Date): string; | ||
static makeDtstamp(dt: Date): string; | ||
static version(): string; | ||
} | ||
} |
{ | ||
"name": "@hebcal/icalendar", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"author": "Michael J. Radwin (https://github.com/mjradwin)", | ||
@@ -27,3 +27,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@hebcal/core": "^3.0.1", | ||
"@hebcal/core": "^3.0.3", | ||
"@hebcal/rest-api": "^3.2.0" | ||
@@ -67,4 +67,4 @@ }, | ||
"@rollup/plugin-node-resolve": "^11.0.1", | ||
"ava": "^3.14.0", | ||
"eslint": "^7.16.0", | ||
"ava": "^3.15.0", | ||
"eslint": "^7.17.0", | ||
"eslint-config-google": "^0.14.0", | ||
@@ -71,0 +71,0 @@ "jsdoc": "^3.6.6", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56837
1289
Updated@hebcal/core@^3.0.3