@sprucelabs/spruce-calendar-components 22.12.1 → 23.0.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.
@@ -10,8 +10,6 @@ import EventRepeatingToolViewController from './tools/EventRepeatingTool.vc';
10
10
  import EventTitleToolViewController from './tools/EventTitleTool.vc';
11
11
  import EventControlsCardViewController from './viewControllers/EventControlsCard.vc';
12
12
  import RepeatingControlsListViewController from './viewControllers/RepeatingControlsList.vc';
13
- export { default as DateParser } from './parsing/DateParser';
14
- export * from './parsing/DateParser';
15
13
  /** COMPONENTS */
16
14
  export { default as RepeatingCardViewController } from './tools/EventRepeatingTool.vc';
17
15
  export * from './tools/EventRepeatingTool.vc';
@@ -4,8 +4,6 @@ export { default as CalendarToolTestFactory } from './toolBelt/CalendarToolTestF
4
4
  export * from './toolBelt/CalendarToolTestFactory.js';
5
5
  export { default as calendarToolBeltInteractor } from './__tests__/support/utilities/calendarToolBeltInteractor.js';
6
6
  export { default as SpyEventManager } from './__tests__/support/SpyEventManager.js';
7
- export { default as DateParser } from './parsing/DateParser.js';
8
- export * from './parsing/DateParser.js';
9
7
  /** COMPONENTS */
10
8
  export { default as RepeatingCardViewController } from './tools/EventRepeatingTool.vc.js';
11
9
  export * from './tools/EventRepeatingTool.vc.js';
@@ -10,8 +10,6 @@ import EventRepeatingToolViewController from './tools/EventRepeatingTool.vc';
10
10
  import EventTitleToolViewController from './tools/EventTitleTool.vc';
11
11
  import EventControlsCardViewController from './viewControllers/EventControlsCard.vc';
12
12
  import RepeatingControlsListViewController from './viewControllers/RepeatingControlsList.vc';
13
- export { default as DateParser } from './parsing/DateParser';
14
- export * from './parsing/DateParser';
15
13
  /** COMPONENTS */
16
14
  export { default as RepeatingCardViewController } from './tools/EventRepeatingTool.vc';
17
15
  export * from './tools/EventRepeatingTool.vc';
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.peopleToPeopleWithoutSchedules = exports.draftEventGenerator = exports.AbstractCalendarEventToolBeltState = exports.CalendarToolRegistrar = exports.EventRepeatingToolViewController = exports.EventDateTimeToolViewController = exports.EventControlsCardViewController = exports.CalendarViewController = exports.RepeatingControlsListViewController = exports.RepeatingCardViewController = exports.DateParser = exports.SpyEventManager = exports.calendarToolBeltInteractor = exports.CalendarToolTestFactory = exports.CalendarToolBeltStateMachineTestFactory = exports.calendarSkillAssert = void 0;
20
+ exports.peopleToPeopleWithoutSchedules = exports.draftEventGenerator = exports.AbstractCalendarEventToolBeltState = exports.CalendarToolRegistrar = exports.EventRepeatingToolViewController = exports.EventDateTimeToolViewController = exports.EventControlsCardViewController = exports.CalendarViewController = exports.RepeatingControlsListViewController = exports.RepeatingCardViewController = exports.SpyEventManager = exports.calendarToolBeltInteractor = exports.CalendarToolTestFactory = exports.CalendarToolBeltStateMachineTestFactory = exports.calendarSkillAssert = void 0;
21
21
  var calendarSkillAssert_1 = require("./__tests__/support/utilities/calendarSkillAssert");
22
22
  Object.defineProperty(exports, "calendarSkillAssert", { enumerable: true, get: function () { return __importDefault(calendarSkillAssert_1).default; } });
23
23
  var CalendarToolBeltStateMachineTestFactory_1 = require("./__tests__/support/CalendarToolBeltStateMachineTestFactory");
@@ -29,9 +29,6 @@ var calendarToolBeltInteractor_1 = require("./__tests__/support/utilities/calend
29
29
  Object.defineProperty(exports, "calendarToolBeltInteractor", { enumerable: true, get: function () { return __importDefault(calendarToolBeltInteractor_1).default; } });
30
30
  var SpyEventManager_1 = require("./__tests__/support/SpyEventManager");
31
31
  Object.defineProperty(exports, "SpyEventManager", { enumerable: true, get: function () { return __importDefault(SpyEventManager_1).default; } });
32
- var DateParser_1 = require("./parsing/DateParser");
33
- Object.defineProperty(exports, "DateParser", { enumerable: true, get: function () { return __importDefault(DateParser_1).default; } });
34
- __exportStar(require("./parsing/DateParser"), exports);
35
32
  /** COMPONENTS */
36
33
  var EventRepeatingTool_vc_1 = require("./tools/EventRepeatingTool.vc");
37
34
  Object.defineProperty(exports, "RepeatingCardViewController", { enumerable: true, get: function () { return __importDefault(EventRepeatingTool_vc_1).default; } });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-calendar-components",
3
3
  "description": "Calendar components for working with calendars and Sprucebot.",
4
- "version": "22.12.1",
4
+ "version": "23.0.0",
5
5
  "skill": {
6
6
  "namespace": "calendar"
7
7
  },
@@ -169,11 +169,7 @@
169
169
  "build/noSchedules/peopleToPeopleWithoutSchedules.js",
170
170
  "build/noSchedules/peopleToPeopleWithoutSchedules.d.ts",
171
171
  "build/esm/noSchedules/peopleToPeopleWithoutSchedules.js",
172
- "build/esm/noSchedules/peopleToPeopleWithoutSchedules.d.ts",
173
- "build/parsing/DateParser.js",
174
- "build/parsing/DateParser.d.ts",
175
- "build/esm/parsing/DateParser.js",
176
- "build/esm/parsing/DateParser.d.ts"
172
+ "build/esm/noSchedules/peopleToPeopleWithoutSchedules.d.ts"
177
173
  ],
178
174
  "keywords": [],
179
175
  "scripts": {
@@ -1,7 +0,0 @@
1
- export default class DateParser {
2
- private now;
3
- private parsers;
4
- private constructor();
5
- static Parser(now: () => number): DateParser;
6
- parse(str: string): number;
7
- }
@@ -1,250 +0,0 @@
1
- import { dateUtil } from '@sprucelabs/calendar-utils';
2
- import { assertOptions } from '@sprucelabs/schema';
3
- export default class DateParser {
4
- constructor(now) {
5
- this.parsers = [];
6
- this.now = now;
7
- const parsers = ParserFactory.Factory(now);
8
- this.parsers = [...parsers.all()];
9
- }
10
- static Parser(now) {
11
- assertOptions({ now }, ['now']);
12
- return new this(now);
13
- }
14
- parse(str) {
15
- const now = this.now();
16
- const date = dateUtil.splitDate(now);
17
- let parsed = str.toLocaleLowerCase().replace(/[^a-z0-9: ]/g, '');
18
- const context = {
19
- hasYear: false,
20
- };
21
- if (str !== 'now') {
22
- for (const parser of this.parsers) {
23
- parsed = parser.parse(parsed, date, context);
24
- }
25
- }
26
- let normalized = dateUtil.date(Object.assign(Object.assign({}, date), { milliseconds: 0, second: 0 }));
27
- return normalized;
28
- }
29
- }
30
- class ParserFactory {
31
- all() {
32
- return [
33
- this.Parser('Year'),
34
- this.Parser('Month'),
35
- this.Parser('Dow'),
36
- this.Parser('Week'),
37
- this.Parser('Time'),
38
- ];
39
- }
40
- constructor(now) {
41
- this.strategies = {
42
- Year: () => new YearParser(this.now),
43
- Month: () => new MonthParser(this.now),
44
- Dow: () => new DowParser(this.now),
45
- Time: () => new TimeParser(this.now),
46
- Week: () => new WeekParser(this.now),
47
- };
48
- this.now = now;
49
- }
50
- static Factory(now) {
51
- return new this(now);
52
- }
53
- Parser(parserType) {
54
- return this.strategies[parserType]();
55
- }
56
- }
57
- class AbstractParser {
58
- constructor(now) {
59
- this.now = now;
60
- }
61
- }
62
- class WeekParser extends AbstractParser {
63
- parse(str, date) {
64
- var _a;
65
- if (str.includes('next week')) {
66
- date.day += 7;
67
- str = str.replace('next week', '');
68
- }
69
- const match = (_a = str.match(/(\d{1,2}) ?(weeks?)/)) === null || _a === void 0 ? void 0 : _a[0];
70
- if (match) {
71
- date.day += parseInt(match, 10) * 7;
72
- str = str.replace(match, '');
73
- }
74
- return str;
75
- }
76
- }
77
- class TimeParser extends AbstractParser {
78
- parse(str, date, context) {
79
- var _a;
80
- const match = (_a = str.match(/(\d{1,2})(:(\d{2}))? ?(am|pm)?/)) === null || _a === void 0 ? void 0 : _a[0];
81
- if (!match) {
82
- return str;
83
- }
84
- if (match) {
85
- date.hour = parseInt(match, 10);
86
- date.minute = 0;
87
- }
88
- if (str.includes(':')) {
89
- date.minute = parseInt(str.split(':')[1], 10);
90
- }
91
- if (str.includes('pm')) {
92
- date.hour += 12;
93
- }
94
- else if (date.hour === 12 && str.includes('am')) {
95
- date.hour = 0;
96
- }
97
- if (!context.hasYear && dateUtil.date(date) < this.now() && str !== 'now') {
98
- date.hour += 12;
99
- }
100
- return str;
101
- }
102
- }
103
- class DowParser extends AbstractParser {
104
- parse(str, date) {
105
- var _a;
106
- if (str.includes('tomorrow')) {
107
- date.day += 1;
108
- str = str.replace('tomorrow', '');
109
- }
110
- const dows = [
111
- {
112
- abbr: 'sun',
113
- full: 'sunday',
114
- },
115
- {
116
- abbr: 'mon',
117
- full: 'monday',
118
- },
119
- {
120
- abbr: 'tue',
121
- full: 'tuesday',
122
- },
123
- {
124
- abbr: 'wed',
125
- full: 'wednesday',
126
- },
127
- {
128
- abbr: 'thu',
129
- full: 'thursday',
130
- },
131
- {
132
- abbr: 'fri',
133
- full: 'friday',
134
- },
135
- {
136
- abbr: 'sat',
137
- full: 'saturday',
138
- },
139
- ];
140
- for (const dow of dows) {
141
- const re = new RegExp(`(^|\\W)${dow.abbr}(\\W|$)`, 'gi');
142
- str = str.replace(re, `$1${dow.full}$2`);
143
- }
144
- const match = (_a = str.match(/(monday|tuesday|wednesday|thursday|friday|saturday|sunday)/)) === null || _a === void 0 ? void 0 : _a[0];
145
- if (match) {
146
- while (dateUtil.format(dateUtil.date(date), 'EEEE').toLocaleLowerCase() !==
147
- match) {
148
- date.day += 1;
149
- str = str.replace(match, '');
150
- }
151
- }
152
- return str;
153
- }
154
- }
155
- class YearParser extends AbstractParser {
156
- parse(str, date, context) {
157
- const matches = str.match(/\d{4}/);
158
- if (matches) {
159
- date.year = parseInt(matches[0], 10);
160
- str = str.replace(matches[0], '');
161
- context.hasYear = true;
162
- }
163
- return str;
164
- }
165
- }
166
- class MonthParser extends AbstractParser {
167
- parse(str, date) {
168
- let normalized = str;
169
- normalized = this.normalizeMonths(normalized);
170
- const matches = normalized.match(/(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) ?(\d+)(?:nd|rd|th|st)?/i);
171
- if (matches) {
172
- date.month = [
173
- 'jan',
174
- 'feb',
175
- 'mar',
176
- 'apr',
177
- 'may',
178
- 'jun',
179
- 'jul',
180
- 'aug',
181
- 'sep',
182
- 'oct',
183
- 'nov',
184
- 'dec',
185
- ].indexOf(matches[1]);
186
- date.day = parseInt(matches[2], 10);
187
- normalized = normalized.replace(matches[0], '');
188
- return normalized;
189
- }
190
- return str;
191
- }
192
- normalizeMonths(normalized) {
193
- const months = [
194
- {
195
- desired: 'jan',
196
- possible: ['january'],
197
- },
198
- {
199
- desired: 'feb',
200
- possible: ['february'],
201
- },
202
- {
203
- desired: 'mar',
204
- possible: ['march'],
205
- },
206
- {
207
- desired: 'apr',
208
- possible: ['april'],
209
- },
210
- {
211
- desired: 'may',
212
- possible: ['may'],
213
- },
214
- {
215
- desired: 'jun',
216
- possible: ['june'],
217
- },
218
- {
219
- desired: 'jul',
220
- possible: ['july'],
221
- },
222
- {
223
- desired: 'aug',
224
- possible: ['august'],
225
- },
226
- {
227
- desired: 'sep',
228
- possible: ['september'],
229
- },
230
- {
231
- desired: 'oct',
232
- possible: ['october'],
233
- },
234
- {
235
- desired: 'nov',
236
- possible: ['november'],
237
- },
238
- {
239
- desired: 'dec',
240
- possible: ['december'],
241
- },
242
- ];
243
- for (const month of months) {
244
- for (const possible of month.possible) {
245
- normalized = normalized.replace(possible, month.desired);
246
- }
247
- }
248
- return normalized;
249
- }
250
- }
@@ -1,7 +0,0 @@
1
- export default class DateParser {
2
- private now;
3
- private parsers;
4
- private constructor();
5
- static Parser(now: () => number): DateParser;
6
- parse(str: string): number;
7
- }
@@ -1,253 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const calendar_utils_1 = require("@sprucelabs/calendar-utils");
4
- const schema_1 = require("@sprucelabs/schema");
5
- class DateParser {
6
- constructor(now) {
7
- this.parsers = [];
8
- this.now = now;
9
- const parsers = ParserFactory.Factory(now);
10
- this.parsers = [...parsers.all()];
11
- }
12
- static Parser(now) {
13
- (0, schema_1.assertOptions)({ now }, ['now']);
14
- return new this(now);
15
- }
16
- parse(str) {
17
- const now = this.now();
18
- const date = calendar_utils_1.dateUtil.splitDate(now);
19
- let parsed = str.toLocaleLowerCase().replace(/[^a-z0-9: ]/g, '');
20
- const context = {
21
- hasYear: false,
22
- };
23
- if (str !== 'now') {
24
- for (const parser of this.parsers) {
25
- parsed = parser.parse(parsed, date, context);
26
- }
27
- }
28
- let normalized = calendar_utils_1.dateUtil.date(Object.assign(Object.assign({}, date), { milliseconds: 0, second: 0 }));
29
- return normalized;
30
- }
31
- }
32
- exports.default = DateParser;
33
- class ParserFactory {
34
- all() {
35
- return [
36
- this.Parser('Year'),
37
- this.Parser('Month'),
38
- this.Parser('Dow'),
39
- this.Parser('Week'),
40
- this.Parser('Time'),
41
- ];
42
- }
43
- constructor(now) {
44
- this.strategies = {
45
- Year: () => new YearParser(this.now),
46
- Month: () => new MonthParser(this.now),
47
- Dow: () => new DowParser(this.now),
48
- Time: () => new TimeParser(this.now),
49
- Week: () => new WeekParser(this.now),
50
- };
51
- this.now = now;
52
- }
53
- static Factory(now) {
54
- return new this(now);
55
- }
56
- Parser(parserType) {
57
- return this.strategies[parserType]();
58
- }
59
- }
60
- class AbstractParser {
61
- constructor(now) {
62
- this.now = now;
63
- }
64
- }
65
- class WeekParser extends AbstractParser {
66
- parse(str, date) {
67
- var _a;
68
- if (str.includes('next week')) {
69
- date.day += 7;
70
- str = str.replace('next week', '');
71
- }
72
- const match = (_a = str.match(/(\d{1,2}) ?(weeks?)/)) === null || _a === void 0 ? void 0 : _a[0];
73
- if (match) {
74
- date.day += parseInt(match, 10) * 7;
75
- str = str.replace(match, '');
76
- }
77
- return str;
78
- }
79
- }
80
- class TimeParser extends AbstractParser {
81
- parse(str, date, context) {
82
- var _a;
83
- const match = (_a = str.match(/(\d{1,2})(:(\d{2}))? ?(am|pm)?/)) === null || _a === void 0 ? void 0 : _a[0];
84
- if (!match) {
85
- return str;
86
- }
87
- if (match) {
88
- date.hour = parseInt(match, 10);
89
- date.minute = 0;
90
- }
91
- if (str.includes(':')) {
92
- date.minute = parseInt(str.split(':')[1], 10);
93
- }
94
- if (str.includes('pm')) {
95
- date.hour += 12;
96
- }
97
- else if (date.hour === 12 && str.includes('am')) {
98
- date.hour = 0;
99
- }
100
- if (!context.hasYear && calendar_utils_1.dateUtil.date(date) < this.now() && str !== 'now') {
101
- date.hour += 12;
102
- }
103
- return str;
104
- }
105
- }
106
- class DowParser extends AbstractParser {
107
- parse(str, date) {
108
- var _a;
109
- if (str.includes('tomorrow')) {
110
- date.day += 1;
111
- str = str.replace('tomorrow', '');
112
- }
113
- const dows = [
114
- {
115
- abbr: 'sun',
116
- full: 'sunday',
117
- },
118
- {
119
- abbr: 'mon',
120
- full: 'monday',
121
- },
122
- {
123
- abbr: 'tue',
124
- full: 'tuesday',
125
- },
126
- {
127
- abbr: 'wed',
128
- full: 'wednesday',
129
- },
130
- {
131
- abbr: 'thu',
132
- full: 'thursday',
133
- },
134
- {
135
- abbr: 'fri',
136
- full: 'friday',
137
- },
138
- {
139
- abbr: 'sat',
140
- full: 'saturday',
141
- },
142
- ];
143
- for (const dow of dows) {
144
- const re = new RegExp(`(^|\\W)${dow.abbr}(\\W|$)`, 'gi');
145
- str = str.replace(re, `$1${dow.full}$2`);
146
- }
147
- const match = (_a = str.match(/(monday|tuesday|wednesday|thursday|friday|saturday|sunday)/)) === null || _a === void 0 ? void 0 : _a[0];
148
- if (match) {
149
- while (calendar_utils_1.dateUtil.format(calendar_utils_1.dateUtil.date(date), 'EEEE').toLocaleLowerCase() !==
150
- match) {
151
- date.day += 1;
152
- str = str.replace(match, '');
153
- }
154
- }
155
- return str;
156
- }
157
- }
158
- class YearParser extends AbstractParser {
159
- parse(str, date, context) {
160
- const matches = str.match(/\d{4}/);
161
- if (matches) {
162
- date.year = parseInt(matches[0], 10);
163
- str = str.replace(matches[0], '');
164
- context.hasYear = true;
165
- }
166
- return str;
167
- }
168
- }
169
- class MonthParser extends AbstractParser {
170
- parse(str, date) {
171
- let normalized = str;
172
- normalized = this.normalizeMonths(normalized);
173
- const matches = normalized.match(/(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) ?(\d+)(?:nd|rd|th|st)?/i);
174
- if (matches) {
175
- date.month = [
176
- 'jan',
177
- 'feb',
178
- 'mar',
179
- 'apr',
180
- 'may',
181
- 'jun',
182
- 'jul',
183
- 'aug',
184
- 'sep',
185
- 'oct',
186
- 'nov',
187
- 'dec',
188
- ].indexOf(matches[1]);
189
- date.day = parseInt(matches[2], 10);
190
- normalized = normalized.replace(matches[0], '');
191
- return normalized;
192
- }
193
- return str;
194
- }
195
- normalizeMonths(normalized) {
196
- const months = [
197
- {
198
- desired: 'jan',
199
- possible: ['january'],
200
- },
201
- {
202
- desired: 'feb',
203
- possible: ['february'],
204
- },
205
- {
206
- desired: 'mar',
207
- possible: ['march'],
208
- },
209
- {
210
- desired: 'apr',
211
- possible: ['april'],
212
- },
213
- {
214
- desired: 'may',
215
- possible: ['may'],
216
- },
217
- {
218
- desired: 'jun',
219
- possible: ['june'],
220
- },
221
- {
222
- desired: 'jul',
223
- possible: ['july'],
224
- },
225
- {
226
- desired: 'aug',
227
- possible: ['august'],
228
- },
229
- {
230
- desired: 'sep',
231
- possible: ['september'],
232
- },
233
- {
234
- desired: 'oct',
235
- possible: ['october'],
236
- },
237
- {
238
- desired: 'nov',
239
- possible: ['november'],
240
- },
241
- {
242
- desired: 'dec',
243
- possible: ['december'],
244
- },
245
- ];
246
- for (const month of months) {
247
- for (const possible of month.possible) {
248
- normalized = normalized.replace(possible, month.desired);
249
- }
250
- }
251
- return normalized;
252
- }
253
- }