@sprucelabs/calendar-utils 42.0.415 → 42.0.417

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.
@@ -9,7 +9,7 @@ class SpruceError extends error_1.default {
9
9
  friendlyMessage() {
10
10
  const { options } = this;
11
11
  let message;
12
- switch (options === null || options === void 0 ? void 0 : options.code) {
12
+ switch (options?.code) {
13
13
  case 'INVALID_TIMEZONE_NAME':
14
14
  message = `Invalid timezone: ${options.name}!`;
15
15
  break;
@@ -56,7 +56,7 @@ class DateUtilDecorator {
56
56
  };
57
57
  }
58
58
  offsetDate(date) {
59
- return this.addOffset(date !== null && date !== void 0 ? date : new Date().getTime(), false);
59
+ return this.addOffset(date ?? new Date().getTime(), false);
60
60
  }
61
61
  addOffset(value, shouldInverse = true) {
62
62
  let offset = this.calculateOffset(value);
@@ -26,7 +26,7 @@ class LocaleImpl extends mercury_event_emitter_1.AbstractEventEmitter {
26
26
  if (onDate || timezone) {
27
27
  const date = onDate ? onDate : Date.now();
28
28
  const dateRoundedToNearestHour = date - (date % 3600000);
29
- const zone = timezone !== null && timezone !== void 0 ? timezone : this.getZoneName();
29
+ const zone = timezone ?? this.getZoneName();
30
30
  const key = `${zone}-${dateRoundedToNearestHour}`;
31
31
  if (!(key in this.offsetsForDate)) {
32
32
  this.offsetsForDate[key] = this.zoneNameToOffsetMinutes(zone, onDate);
@@ -7,7 +7,6 @@ const date_utility_1 = __importDefault(require("../../utilities/date.utility"));
7
7
  const AbstractParser_1 = require("../AbstractParser");
8
8
  class DowParser extends AbstractParser_1.AbstractParser {
9
9
  parse(str, date) {
10
- var _a;
11
10
  if (str.includes('tomorrow')) {
12
11
  date.day += 1;
13
12
  str = str.replace('tomorrow', '');
@@ -46,7 +45,7 @@ class DowParser extends AbstractParser_1.AbstractParser {
46
45
  const re = new RegExp(`(^|\\W)${dow.abbr}(\\W|$)`, 'gi');
47
46
  str = str.replace(re, `$1${dow.full}$2`);
48
47
  }
49
- const match = (_a = str.match(/(monday|tuesday|wednesday|thursday|friday|saturday|sunday)/)) === null || _a === void 0 ? void 0 : _a[0];
48
+ const match = str.match(/(monday|tuesday|wednesday|thursday|friday|saturday|sunday)/)?.[0];
50
49
  if (match) {
51
50
  while (date_utility_1.default
52
51
  .format(date_utility_1.default.date(date), 'EEEE')
@@ -7,8 +7,7 @@ const date_utility_1 = __importDefault(require("../../utilities/date.utility"));
7
7
  const AbstractParser_1 = require("../AbstractParser");
8
8
  class TimeParser extends AbstractParser_1.AbstractParser {
9
9
  parse(str, date, context) {
10
- var _a;
11
- const matches = (_a = str.match(/(\d{1,2})(:?(\d{1,2}))?\s*([ap]m?)?/)) !== null && _a !== void 0 ? _a : [];
10
+ const matches = str.match(/(\d{1,2})(:?(\d{1,2}))?\s*([ap]m?)?/) ?? [];
12
11
  let [match, hour, , minutes, ampm] = matches;
13
12
  if (!match) {
14
13
  return str;
@@ -16,7 +15,7 @@ class TimeParser extends AbstractParser_1.AbstractParser {
16
15
  if (hour) {
17
16
  let parsedHour = parseInt(hour, 10);
18
17
  if (parsedHour > 12) {
19
- minutes = hour[1] + (minutes !== null && minutes !== void 0 ? minutes : '');
18
+ minutes = hour[1] + (minutes ?? '');
20
19
  hour = hour[0];
21
20
  parsedHour = parseInt(hour, 10);
22
21
  }
@@ -29,7 +28,7 @@ class TimeParser extends AbstractParser_1.AbstractParser {
29
28
  }
30
29
  date.minute = parseInt(minutes, 10);
31
30
  }
32
- if (ampm === null || ampm === void 0 ? void 0 : ampm.includes('p')) {
31
+ if (ampm?.includes('p')) {
33
32
  date.hour += 12;
34
33
  }
35
34
  else if (date.hour === 12 && match.includes('am')) {
@@ -3,12 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const AbstractParser_1 = require("../AbstractParser");
4
4
  class WeekParser extends AbstractParser_1.AbstractParser {
5
5
  parse(str, date) {
6
- var _a;
7
6
  if (str.includes('next week')) {
8
7
  date.day += 7;
9
8
  str = str.replace('next week', '');
10
9
  }
11
- const match = (_a = str.match(/(\d{1,2}) ?(weeks?)/)) === null || _a === void 0 ? void 0 : _a[0];
10
+ const match = str.match(/(\d{1,2}) ?(weeks?)/)?.[0];
12
11
  if (match) {
13
12
  date.day += parseInt(match, 10) * 7;
14
13
  str = str.replace(match, '');
@@ -31,7 +31,7 @@ class PeopleSorter {
31
31
  }
32
32
  peopleExcluding(selectedPeopleWithValidEvents) {
33
33
  return this.people.filter((p) => {
34
- const match = selectedPeopleWithValidEvents.find((sp) => (sp === null || sp === void 0 ? void 0 : sp.id) === p.id);
34
+ const match = selectedPeopleWithValidEvents.find((sp) => sp?.id === p.id);
35
35
  if (match) {
36
36
  return false;
37
37
  }
@@ -96,12 +96,10 @@ class PeopleSorter {
96
96
  }
97
97
  }
98
98
  get people() {
99
- var _a;
100
- return (_a = this._people) !== null && _a !== void 0 ? _a : [];
99
+ return this._people ?? [];
101
100
  }
102
101
  get events() {
103
- var _a;
104
- return (_a = this._events) !== null && _a !== void 0 ? _a : [];
102
+ return this._events ?? [];
105
103
  }
106
104
  }
107
105
  exports.default = PeopleSorter;
@@ -32,13 +32,13 @@ class RepeatingRuleTextGenerator {
32
32
  .map((d) => this.downMap[d])
33
33
  .join(', ')}`;
34
34
  }
35
- else if ((interval !== null && interval !== void 0 ? interval : 0) > 1) {
35
+ else if ((interval ?? 0) > 1) {
36
36
  message = `Repeats every ${interval} ${this.unitMap[repeats]}`;
37
37
  }
38
38
  else {
39
39
  message = `Repeats ${repeats}`;
40
40
  }
41
- const until = activeUntilDate !== null && activeUntilDate !== void 0 ? activeUntilDate : repeatsUntil;
41
+ const until = activeUntilDate ?? repeatsUntil;
42
42
  if (until) {
43
43
  message += ` until ${this.dates.formatDate(until)}.`;
44
44
  }
@@ -29,7 +29,6 @@ const calendarUtil = {
29
29
  return excludedEvents;
30
30
  },
31
31
  applyRuleAndGetEventsWithoutExclusion(e, dateUntil, timezone) {
32
- var _a, _b, _c, _d;
33
32
  let repeatsUntil;
34
33
  if (e.repeats) {
35
34
  if (e.repeatsUntil) {
@@ -45,13 +44,13 @@ const calendarUtil = {
45
44
  const dtstart = (0, rrule_1.datetime)(startSplit.year, startSplit.month + 1, startSplit.day, startSplit.hour, startSplit.minute);
46
45
  const rule = new rrule_1.RRule({
47
46
  freq: this.freqMapToRRule[e.repeats],
48
- interval: (_a = e.interval) !== null && _a !== void 0 ? _a : 1,
49
- byweekday: (_b = e.daysOfWeek) === null || _b === void 0 ? void 0 : _b.map((d) => this.weekDaysMapToRRuleDays[d]),
47
+ interval: e.interval ?? 1,
48
+ byweekday: e.daysOfWeek?.map((d) => this.weekDaysMapToRRuleDays[d]),
50
49
  dtstart,
51
- bymonthday: (_c = e.daysOfMonth) === null || _c === void 0 ? void 0 : _c.map((d) => parseInt(d)),
50
+ bymonthday: e.daysOfMonth?.map((d) => parseInt(d)),
52
51
  until: new Date(repeatsUntil),
53
52
  count: e.occurrences,
54
- bysetpos: (_d = e.nthOccurrences) === null || _d === void 0 ? void 0 : _d.map((o) => {
53
+ bysetpos: e.nthOccurrences?.map((o) => {
55
54
  if (o >= 0) {
56
55
  ++o;
57
56
  }
@@ -163,11 +163,10 @@ const dateUtil = {
163
163
  return this.addMonths(this.getStartOfMonth(timestamp), count);
164
164
  },
165
165
  date(date) {
166
- var _a, _b, _c, _d;
167
166
  if (!date) {
168
167
  return new Date().getTime();
169
168
  }
170
- return Date.UTC(date.year, date.month, date.day, (_a = date.hour) !== null && _a !== void 0 ? _a : 0, (_b = date.minute) !== null && _b !== void 0 ? _b : 0, (_c = date.second) !== null && _c !== void 0 ? _c : 0, (_d = date.milliseconds) !== null && _d !== void 0 ? _d : 0);
169
+ return Date.UTC(date.year, date.month, date.day, date.hour ?? 0, date.minute ?? 0, date.second ?? 0, date.milliseconds ?? 0);
171
170
  },
172
171
  /**
173
172
  * Unit_______________Pattern___Results
@@ -32,7 +32,7 @@ const durationUtil = {
32
32
  return durationStr.trim();
33
33
  },
34
34
  renderDateTimeUntil(end, prefixes) {
35
- const { today = null, tomorrow = null, yesterday = null, future = null, past = null, shouldCapitalize, now = Date.now(), } = prefixes !== null && prefixes !== void 0 ? prefixes : {};
35
+ const { today = null, tomorrow = null, yesterday = null, future = null, past = null, shouldCapitalize, now = Date.now(), } = prefixes ?? {};
36
36
  let prefix = today;
37
37
  let startDateAndTime = 'today';
38
38
  const daysFromNow = Math.round((this.dates.getStartOfDay(end) - this.dates.getStartOfDay(now)) /
@@ -8,11 +8,10 @@ const schema_1 = require("@sprucelabs/schema");
8
8
  const spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
9
9
  const TimezoneChoiceSorter_1 = __importDefault(require("../locales/TimezoneChoiceSorter"));
10
10
  function sortTimezoneChoices(locale, schema, fieldName) {
11
- var _a;
12
11
  const sorter = new TimezoneChoiceSorter_1.default(locale);
13
12
  const choices = sorter.sort(spruce_core_schemas_1.timezoneChoices);
14
13
  const copy = (0, schema_1.cloneDeep)(schema);
15
- const field = (_a = copy.fields) === null || _a === void 0 ? void 0 : _a[fieldName];
14
+ const field = copy.fields?.[fieldName];
16
15
  if (field) {
17
16
  field.options = {
18
17
  ...field.options,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "42.0.415",
6
+ "version": "42.0.417",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",
@@ -61,25 +61,25 @@
61
61
  "watch.rebuild": "yarn run clean.all && yarn install && yarn run watch.build.dev"
62
62
  },
63
63
  "dependencies": {
64
- "@sprucelabs/error": "^6.0.477",
65
- "@sprucelabs/mercury-event-emitter": "^42.0.527",
66
- "@sprucelabs/mercury-types": "^47.0.528",
67
- "@sprucelabs/schema": "^30.0.486",
68
- "@sprucelabs/spruce-core-schemas": "^40.1.472",
69
- "@sprucelabs/spruce-event-utils": "^40.1.248",
64
+ "@sprucelabs/error": "^6.0.480",
65
+ "@sprucelabs/mercury-event-emitter": "^42.0.529",
66
+ "@sprucelabs/mercury-types": "^47.0.530",
67
+ "@sprucelabs/schema": "^30.0.489",
68
+ "@sprucelabs/spruce-core-schemas": "^40.1.475",
69
+ "@sprucelabs/spruce-event-utils": "^40.1.250",
70
70
  "date-fns": "^4.1.0",
71
71
  "date-fns-tz": "^3.2.0",
72
72
  "rrule": "^2.8.1"
73
73
  },
74
74
  "devDependencies": {
75
- "@sprucelabs/esm-postbuild": "^6.0.461",
76
- "@sprucelabs/jest-json-reporter": "^8.0.477",
77
- "@sprucelabs/resolve-path-aliases": "^2.0.456",
75
+ "@sprucelabs/esm-postbuild": "^6.0.463",
76
+ "@sprucelabs/jest-json-reporter": "^8.0.481",
77
+ "@sprucelabs/resolve-path-aliases": "^2.0.458",
78
78
  "@sprucelabs/semantic-release": "^5.0.2",
79
- "@sprucelabs/test": "^9.0.50",
80
- "@sprucelabs/test-utils": "^5.1.427",
79
+ "@sprucelabs/test": "^9.0.51",
80
+ "@sprucelabs/test-utils": "^5.1.433",
81
81
  "@types/lodash": "^4.17.10",
82
- "@types/node": "^22.7.5",
82
+ "@types/node": "^22.7.6",
83
83
  "chokidar-cli": "^3.0.0",
84
84
  "dotenv": "^16.4.5",
85
85
  "eslint": "^9.12.0",
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "skipLibCheck": true,
4
4
  "module": "commonjs",
5
5
  "esModuleInterop": true,
6
- "target": "ES2019",
6
+ "target": "ES2020",
7
7
  "lib": [
8
8
  "DOM",
9
9
  "ES2022"