@sprucelabs/calendar-utils 39.0.292 → 40.0.1

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 (59) hide show
  1. package/build/.spruce/errors/calendarUtils/invalidTimezoneName.schema.js +3 -3
  2. package/build/.spruce/errors/errors.types.d.ts +2 -2
  3. package/build/.spruce/errors/errors.types.js +0 -2
  4. package/build/.spruce/errors/options.types.d.ts +2 -2
  5. package/build/.spruce/schemas/calendarUtils/v2021_05_19/calendarEvent.schema.js +121 -59
  6. package/build/.spruce/schemas/calendarUtils/v2021_05_19/calendarEventLineIcon.schema.js +175 -5
  7. package/build/.spruce/schemas/calendarUtils/v2021_05_19/calendarEventTarget.schema.js +11 -11
  8. package/build/.spruce/schemas/calendarUtils/v2021_05_19/eventExclusionDate.schema.js +7 -7
  9. package/build/.spruce/schemas/calendarUtils/v2021_05_19/eventTimeBlock.schema.js +13 -13
  10. package/build/.spruce/schemas/fields/fields.types.d.ts +1 -1
  11. package/build/.spruce/schemas/schemas.types.d.ts +840 -648
  12. package/build/.spruce/schemas/schemas.types.js +0 -2
  13. package/build/errors/SpruceError.d.ts +1 -1
  14. package/build/errors/SpruceError.js +1 -1
  15. package/build/esm/.spruce/errors/errors.types.d.ts +2 -2
  16. package/build/esm/.spruce/errors/errors.types.js +0 -2
  17. package/build/esm/.spruce/errors/options.types.d.ts +2 -2
  18. package/build/esm/.spruce/schemas/calendarUtils/v2021_05_19/calendarEvent.schema.js +121 -59
  19. package/build/esm/.spruce/schemas/calendarUtils/v2021_05_19/calendarEventLineIcon.schema.js +175 -5
  20. package/build/esm/.spruce/schemas/calendarUtils/v2021_05_19/calendarEventTarget.schema.js +11 -11
  21. package/build/esm/.spruce/schemas/calendarUtils/v2021_05_19/eventExclusionDate.schema.js +7 -7
  22. package/build/esm/.spruce/schemas/calendarUtils/v2021_05_19/eventTimeBlock.schema.js +13 -13
  23. package/build/esm/.spruce/schemas/schemas.types.d.ts +840 -648
  24. package/build/esm/.spruce/schemas/schemas.types.js +0 -2
  25. package/build/esm/constants.d.ts +2 -2
  26. package/build/esm/errors/SpruceError.d.ts +1 -1
  27. package/build/esm/index.d.ts +1 -1
  28. package/build/esm/locales/Locale.js +1 -1
  29. package/build/esm/parsing/strategies/DowParser.js +3 -2
  30. package/build/esm/schemas/v2021_05_19/calendarEvent.builder.d.ts +8 -8
  31. package/build/esm/types/calendar.types.d.ts +3 -3
  32. package/build/esm/utilities/PeopleSorter.d.ts +2 -2
  33. package/build/esm/utilities/PeopleSorter.js +3 -1
  34. package/build/esm/utilities/calendar.utility.d.ts +3 -3
  35. package/build/esm/utilities/date.utility.js +1 -1
  36. package/build/esm/utilities/duration.utility.d.ts +3 -1
  37. package/build/esm/utilities/duration.utility.js +3 -2
  38. package/build/index.d.ts +1 -1
  39. package/build/locales/DateUtilDecorator.js +25 -12
  40. package/build/locales/Locale.js +7 -5
  41. package/build/locales/TimezoneChoiceSorter.js +1 -0
  42. package/build/parsing/AbstractParser.js +2 -0
  43. package/build/parsing/DateParser.js +8 -2
  44. package/build/parsing/ParserFactory.js +9 -7
  45. package/build/parsing/strategies/DowParser.js +4 -4
  46. package/build/parsing/strategies/TimeParser.js +3 -4
  47. package/build/parsing/strategies/WeekParser.js +1 -2
  48. package/build/schemas/v2021_05_19/calendarEvent.builder.js +5 -2
  49. package/build/types/calendar.types.d.ts +3 -3
  50. package/build/utilities/PeopleSorter.d.ts +2 -2
  51. package/build/utilities/PeopleSorter.js +9 -9
  52. package/build/utilities/RepeatingRuleTextGenerator.js +17 -16
  53. package/build/utilities/calendar.utility.js +10 -6
  54. package/build/utilities/date.utility.js +2 -3
  55. package/build/utilities/duration.utility.d.ts +3 -1
  56. package/build/utilities/duration.utility.js +4 -3
  57. package/build/utilities/sortTimezoneChoices.js +5 -3
  58. package/package.json +21 -22
  59. package/tsconfig.json +3 -4
@@ -79,10 +79,13 @@ exports.default = (0, schema_1.buildSchema)({
79
79
  options: {
80
80
  schema: {
81
81
  id: 'calendarEventTarget',
82
- fields: Object.assign(Object.assign({}, spruce_event_utils_1.eventTargetSchema.fields), { personId: {
82
+ fields: {
83
+ ...spruce_event_utils_1.eventTargetSchema.fields,
84
+ personId: {
83
85
  type: 'id',
84
86
  isRequired: true,
85
- } }),
87
+ },
88
+ },
86
89
  },
87
90
  },
88
91
  },
@@ -1,5 +1,5 @@
1
1
  import { timezoneChoices } from '@sprucelabs/spruce-core-schemas';
2
- import { SpruceSchemas } from "./../.spruce/schemas/schemas.types";
2
+ import { SpruceSchemas } from './../.spruce/schemas/schemas.types';
3
3
  import LocaleImpl from '../locales/Locale';
4
4
  import dateUtil from '../utilities/date.utility';
5
5
  type D = typeof dateUtil;
@@ -16,11 +16,11 @@ export type TimezoneChoices = typeof timezoneChoices;
16
16
  export type TimezoneName = TimezoneChoices[number]['value'];
17
17
  export type Repeats = NonNullable<CalendarEvent['repeats']>;
18
18
  export type Locale = Pick<LocaleImpl, 'on' | 'getZoneName' | 'offsetMinutesToZoneName' | 'getTimezoneOffsetMinutes' | 'setTimezoneOffsetMinutes' | 'setZoneName' | 'zoneNameToOffsetMinutes'>;
19
- export type SorterCalendarEvent = {
19
+ export interface SorterCalendarEvent {
20
20
  id: string;
21
21
  groupId?: string;
22
22
  startDateTimeMs: number;
23
23
  personId: string;
24
- };
24
+ }
25
25
  export type RepeatingCalendarEvent = Pick<CalendarEvent, 'repeats' | 'repeatsUntil' | 'daysOfWeek' | 'daysOfMonth' | 'interval' | 'startDateTimeMs' | 'occurrences' | 'nthOccurrences' | 'timeBlocks' | 'nthInRepeating' | 'totalInRepeating'>;
26
26
  export {};
@@ -18,7 +18,7 @@ export default class PeopleSorter {
18
18
  private get people();
19
19
  private get events();
20
20
  }
21
- export type Person = {
21
+ export interface Person {
22
22
  id: string;
23
23
  casualName: string;
24
- };
24
+ }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class PeopleSorter {
4
- constructor() {
5
- this.selectedEvents = [];
6
- }
4
+ _people;
5
+ _events;
6
+ selectedEvents = [];
7
7
  setPeople(people) {
8
8
  this._people = [...people];
9
9
  }
@@ -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
  }
@@ -50,7 +50,9 @@ class PeopleSorter {
50
50
  }
51
51
  return false;
52
52
  });
53
- const groupsIds = selectedEvents.map((e) => e.groupId).filter((g) => !!g);
53
+ const groupsIds = selectedEvents
54
+ .map((e) => e.groupId)
55
+ .filter((g) => !!g);
54
56
  const matchOnGroup = groupsIds.length > 0
55
57
  ? this.events.filter((e) => !selectedEvents.find((se) => se.id === e.id) &&
56
58
  groupsIds.indexOf(e.groupId) > -1)
@@ -94,12 +96,10 @@ class PeopleSorter {
94
96
  }
95
97
  }
96
98
  get people() {
97
- var _a;
98
- return (_a = this._people) !== null && _a !== void 0 ? _a : [];
99
+ return this._people ?? [];
99
100
  }
100
101
  get events() {
101
- var _a;
102
- return (_a = this._events) !== null && _a !== void 0 ? _a : [];
102
+ return this._events ?? [];
103
103
  }
104
104
  }
105
105
  exports.default = PeopleSorter;
@@ -2,21 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const schema_1 = require("@sprucelabs/schema");
4
4
  class RepeatingRuleTextGenerator {
5
+ unitMap = {
6
+ daily: 'days',
7
+ weekly: 'weeks',
8
+ monthly: 'months',
9
+ };
10
+ downMap = {
11
+ sun: 'Sundays',
12
+ mon: 'Mondays',
13
+ tue: 'Tuesdays',
14
+ wed: 'Wednesdays',
15
+ thur: 'Thursdays',
16
+ fri: 'Fridays',
17
+ sat: 'Saturdays',
18
+ };
19
+ dates;
5
20
  constructor(dates) {
6
- this.unitMap = {
7
- daily: 'days',
8
- weekly: 'weeks',
9
- monthly: 'months',
10
- };
11
- this.downMap = {
12
- sun: 'Sundays',
13
- mon: 'Mondays',
14
- tue: 'Tuesdays',
15
- wed: 'Wednesdays',
16
- thur: 'Thursdays',
17
- fri: 'Fridays',
18
- sat: 'Saturdays',
19
- };
20
21
  this.dates = dates;
21
22
  }
22
23
  static Generator(options) {
@@ -32,13 +33,13 @@ class RepeatingRuleTextGenerator {
32
33
  .map((d) => this.downMap[d])
33
34
  .join(', ')}`;
34
35
  }
35
- else if ((interval !== null && interval !== void 0 ? interval : 0) > 1) {
36
+ else if ((interval ?? 0) > 1) {
36
37
  message = `Repeats every ${interval} ${this.unitMap[repeats]}`;
37
38
  }
38
39
  else {
39
40
  message = `Repeats ${repeats}`;
40
41
  }
41
- const until = activeUntilDate !== null && activeUntilDate !== void 0 ? activeUntilDate : repeatsUntil;
42
+ const until = activeUntilDate ?? repeatsUntil;
42
43
  if (until) {
43
44
  message += ` until ${this.dates.formatDate(until)}.`;
44
45
  }
@@ -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
  }
@@ -69,7 +68,12 @@ const calendarUtil = {
69
68
  const iosDate = date_utility_1.default.splitDate(r.getTime());
70
69
  const startDateTimeMs = date_utility_1.default.date(iosDate);
71
70
  const offset = (0, DateUtilDecorator_1.calculateOffsetAtDate)(iosDate, this.locale, timezone);
72
- return Object.assign(Object.assign({}, e), { nthInRepeating: idx, totalInRepeating: allEvents.length, startDateTimeMs: startDateTimeMs - offset });
71
+ return {
72
+ ...e,
73
+ nthInRepeating: idx,
74
+ totalInRepeating: allEvents.length,
75
+ startDateTimeMs: startDateTimeMs - offset,
76
+ };
73
77
  });
74
78
  return events;
75
79
  },
@@ -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
@@ -546,7 +545,7 @@ const dateUtil = {
546
545
  },
547
546
  isSameDay(timestamp1, timestamp2) {
548
547
  const { day, year, month } = this.splitDate(timestamp1);
549
- const { day: day2, year: year2, month: month2 } = this.splitDate(timestamp2);
548
+ const { day: day2, year: year2, month: month2, } = this.splitDate(timestamp2);
550
549
  return day === day2 && year === year2 && month === month2;
551
550
  },
552
551
  getTotalDaysInMonth(year, month) {
@@ -3,7 +3,9 @@ declare const durationUtil: {
3
3
  eventDaysOfWeek: {
4
4
  sun: string;
5
5
  mon: string;
6
- tue: string;
6
+ tue: string; /**
7
+ * @deprecated durationUtil.msToFriendly(...) -> durationUtil.renderDuration(...)
8
+ */
7
9
  wed: string;
8
10
  thur: string;
9
11
  fri: string;
@@ -44,7 +44,7 @@ const durationUtil = {
44
44
  return this.renderDateTimeUntil(start, new Date().getTime(), prefixes);
45
45
  },
46
46
  renderDateTimeUntil(start, now, prefixes) {
47
- const { today = null, tomorrow = null, yesterday = null, future = null, past = null, shouldCapitalize, } = prefixes !== null && prefixes !== void 0 ? prefixes : {};
47
+ const { today = null, tomorrow = null, yesterday = null, future = null, past = null, shouldCapitalize, } = prefixes ?? {};
48
48
  let prefix = today;
49
49
  let startDateAndTime = 'today';
50
50
  const daysFromNow = Math.round((start - now) / (1000 * 3600 * 24));
@@ -64,13 +64,14 @@ const durationUtil = {
64
64
  else if (daysFromNow < -1) {
65
65
  prefix = past;
66
66
  startDateAndTime =
67
- this.dates.format(start, 'MMM do') + ` (${daysFromNow * -1} days ago)`;
67
+ this.dates.format(start, 'MMM do') +
68
+ ` (${daysFromNow * -1} days ago)`;
68
69
  }
69
70
  startDateAndTime += ` @ ${this.dates.format(start, 'h:mmaaa')}`.replace(':00', '');
70
71
  return optionallUcFirst(`${prefix ? `${prefix} ` : ''}${startDateAndTime}`, shouldCapitalize);
71
72
  },
72
73
  renderTimeRange(date1, date2) {
73
- return this.dates.formatTime(date1) + ' to ' + this.dates.formatTime(date2);
74
+ return (this.dates.formatTime(date1) + ' to ' + this.dates.formatTime(date2));
74
75
  },
75
76
  };
76
77
  exports.default = durationUtil;
@@ -7,13 +7,15 @@ const schema_1 = require("@sprucelabs/schema");
7
7
  const spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
8
8
  const TimezoneChoiceSorter_1 = __importDefault(require("../locales/TimezoneChoiceSorter"));
9
9
  function sortTimezoneChoices(locale, schema, fieldName) {
10
- var _a;
11
10
  const sorter = new TimezoneChoiceSorter_1.default(locale);
12
11
  const choices = sorter.sort(spruce_core_schemas_1.timezoneChoices);
13
12
  const copy = (0, schema_1.cloneDeep)(schema);
14
- const field = (_a = copy.fields) === null || _a === void 0 ? void 0 : _a[fieldName];
13
+ const field = copy.fields?.[fieldName];
15
14
  if (field) {
16
- field.options = Object.assign(Object.assign({}, field.options), { choices });
15
+ field.options = {
16
+ ...field.options,
17
+ choices,
18
+ };
17
19
  }
18
20
  return copy;
19
21
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "39.0.292",
6
+ "version": "40.0.1",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",
@@ -19,8 +19,7 @@
19
19
  "namespace": "calendar-utils",
20
20
  "upgradeIgnoreList": [
21
21
  "@sprucelabs/spruce-skill-utils",
22
- "@sprucelabs/spruce-test-fixtures",
23
- "date-fns"
22
+ "@sprucelabs/spruce-test-fixtures"
24
23
  ],
25
24
  "commandOverrides": {
26
25
  "sync.schemas": "--shouldFetchCoreSchemas false --moduleToImportFromWhenRemote @sprucelabs/calendar-utils"
@@ -47,8 +46,8 @@
47
46
  "clean.build": "rm -rf build/",
48
47
  "clean.dependencies": "rm -rf node_modules/ package-lock.json yarn.lock",
49
48
  "clean.dist": "rm -rf build/__tests__ build/esm/__tests__",
50
- "fix.lint": "eslint --fix --cache '**/*.ts'",
51
- "lint": "eslint --cache '**/*.ts'",
49
+ "fix.lint": "eslint --fix --cache",
50
+ "lint": "eslint --cache",
52
51
  "rebuild": "yarn clean.all && yarn && yarn build.dev",
53
52
  "release": "semantic-release",
54
53
  "resolve-paths.lint": "yarn build.resolve-paths ; yarn lint",
@@ -66,37 +65,37 @@
66
65
  "watch.rebuild": "yarn clean.all && yarn && yarn watch.build.dev"
67
66
  },
68
67
  "dependencies": {
69
- "@sprucelabs/error": "^5.1.108",
70
- "@sprucelabs/mercury-event-emitter": "^41.0.384",
71
- "@sprucelabs/mercury-types": "^46.0.300",
72
- "@sprucelabs/schema": "^29.4.60",
73
- "@sprucelabs/spruce-core-schemas": "^39.0.294",
74
- "@sprucelabs/spruce-event-utils": "^38.1.42",
75
- "date-fns": "2.30.0",
76
- "date-fns-tz": "^2.0.1",
68
+ "@sprucelabs/error": "^6.0.1",
69
+ "@sprucelabs/mercury-event-emitter": "^42.0.1",
70
+ "@sprucelabs/mercury-types": "^47.0.0",
71
+ "@sprucelabs/schema": "^30.0.1",
72
+ "@sprucelabs/spruce-core-schemas": "^40.0.0",
73
+ "@sprucelabs/spruce-event-utils": "^40.0.0",
74
+ "date-fns": "^3.6.0",
75
+ "date-fns-tz": "^3.1.2",
77
76
  "rrule": "^2.8.1"
78
77
  },
79
78
  "devDependencies": {
80
- "@sprucelabs/esm-postbuild": "^5.0.200",
79
+ "@sprucelabs/esm-postbuild": "^6.0.1",
81
80
  "@sprucelabs/jest-json-reporter": "^7.0.207",
82
- "@sprucelabs/resolve-path-aliases": "^1.1.304",
83
- "@sprucelabs/semantic-release": "^4.0.8",
84
- "@sprucelabs/test": "^8.0.50",
85
- "@sprucelabs/test-utils": "^4.0.157",
81
+ "@sprucelabs/resolve-path-aliases": "^2.0.3",
82
+ "@sprucelabs/semantic-release": "^5.0.1",
83
+ "@sprucelabs/test": "^9.0.2",
84
+ "@sprucelabs/test-utils": "^5.0.1",
86
85
  "@types/lodash": "^4.17.0",
87
- "@types/node": "^20.12.4",
86
+ "@types/node": "^20.12.7",
88
87
  "chokidar-cli": "^3.0.0",
89
88
  "concurrently": "^8.2.2",
90
89
  "dotenv": "^16.4.5",
91
- "eslint": "^8.57.0",
92
- "eslint-config-spruce": "^10.13.6",
90
+ "eslint": "^9.0.0",
91
+ "eslint-config-spruce": "^11.2.5",
93
92
  "jest": "^29.7.0",
94
93
  "jest-circus": "^29.7.0",
95
94
  "prettier": "^3.2.5",
96
95
  "ts-node": "^10.9.2",
97
96
  "tsc-watch": "^6.2.0",
98
97
  "tsconfig-paths": "^4.2.0",
99
- "typescript": "^5.4.4",
98
+ "typescript": "^5.4.5",
100
99
  "yarn-upgrade-all": "^0.7.2"
101
100
  },
102
101
  "jest": {
package/tsconfig.json CHANGED
@@ -3,11 +3,10 @@
3
3
  "skipLibCheck": true,
4
4
  "module": "commonjs",
5
5
  "esModuleInterop": true,
6
- "target": "ES2017",
6
+ "target": "ES2022",
7
7
  "lib": [
8
8
  "DOM",
9
- "es2017",
10
- "ES2020"
9
+ "ES2022"
11
10
  ],
12
11
  "declaration": true,
13
12
  "noImplicitAny": true,
@@ -37,4 +36,4 @@
37
36
  "build",
38
37
  "esm"
39
38
  ]
40
- }
39
+ }