@arc-js/config-manager 0.0.94 → 0.0.95
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.
- package/config.d.ts +12 -9
- package/config.js +902 -5
- package/config.min.js +1 -1
- package/core/ConfigService.d.ts +23 -7
- package/core/ConfigService.js +1018 -54
- package/core/ConfigService.min.js +1 -1
- package/{types.d.ts → core/types.d.ts} +7 -5
- package/hooks/useConfig.jsx +23 -16
- package/hooks/useConfig.tsx +26 -18
- package/index.d.ts +17 -0
- package/index.js +896 -0
- package/index.min.js +2 -0
- package/package.json +3 -2
- package/providers/ConfigProvider.jsx +61 -32
- package/providers/ConfigProvider.tsx +123 -79
- package/utils/loaders.d.ts +8 -11
- package/utils/loaders.js +21 -32
- package/utils/loaders.min.js +1 -1
- package/utils.d.ts +23 -0
- package/utils.js +94 -0
- package/utils.min.js +2 -0
- /package/{types.js → core/types.js} +0 -0
- /package/{types.min.js → core/types.min.js} +0 -0
package/core/ConfigService.js
CHANGED
|
@@ -8,7 +8,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
8
8
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
9
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
10
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg,
|
|
11
|
+
step((generator = generator.apply(thisArg, [])).next());
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -17,6 +17,901 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
17
17
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
var cooks = {};
|
|
21
|
+
|
|
22
|
+
var timez = {};
|
|
23
|
+
|
|
24
|
+
var hasRequiredTimez;
|
|
25
|
+
|
|
26
|
+
function requireTimez () {
|
|
27
|
+
if (hasRequiredTimez) return timez;
|
|
28
|
+
hasRequiredTimez = 1;
|
|
29
|
+
|
|
30
|
+
Object.defineProperty(timez, '__esModule', { value: true });
|
|
31
|
+
|
|
32
|
+
class Timez {
|
|
33
|
+
constructor(input, enableException = false) {
|
|
34
|
+
if (this.dateChecker(input) === false) {
|
|
35
|
+
this._date = undefined;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (input instanceof Timez && !!input && !!(input === null || input === void 0 ? void 0 : input._date)) {
|
|
39
|
+
this._date = new Date(input === null || input === void 0 ? void 0 : input._date);
|
|
40
|
+
}
|
|
41
|
+
else if (input instanceof Date) {
|
|
42
|
+
this._date = new Date(input);
|
|
43
|
+
}
|
|
44
|
+
else if (typeof input === 'string') {
|
|
45
|
+
this._date = Timez.parseString(input, enableException);
|
|
46
|
+
}
|
|
47
|
+
else if (typeof input === 'number') {
|
|
48
|
+
this._date = new Date(input);
|
|
49
|
+
}
|
|
50
|
+
else if (input === undefined ||
|
|
51
|
+
input === null ||
|
|
52
|
+
(typeof input === 'number' && isNaN(input))) {
|
|
53
|
+
this._date = new Date();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this._date = undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
static now() {
|
|
61
|
+
return new Timez();
|
|
62
|
+
}
|
|
63
|
+
static parse(dateString, format) {
|
|
64
|
+
if (typeof format === 'string' &&
|
|
65
|
+
format.length > 0 && ((dateString instanceof Timez &&
|
|
66
|
+
!!dateString &&
|
|
67
|
+
!!(dateString === null || dateString === void 0 ? void 0 : dateString._date)) ||
|
|
68
|
+
dateString instanceof Date ||
|
|
69
|
+
typeof dateString === 'string' ||
|
|
70
|
+
typeof dateString === 'number' || (dateString === undefined ||
|
|
71
|
+
dateString === null ||
|
|
72
|
+
(typeof dateString === 'number' && isNaN(dateString))))) {
|
|
73
|
+
return Timez.parseWithFormat(dateString, format) || new Timez(dateString);
|
|
74
|
+
}
|
|
75
|
+
return new Timez(dateString);
|
|
76
|
+
}
|
|
77
|
+
static unix(timestamp) {
|
|
78
|
+
return new Timez(timestamp * 1000);
|
|
79
|
+
}
|
|
80
|
+
static utc() {
|
|
81
|
+
const now = new Date();
|
|
82
|
+
return new Timez(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds()));
|
|
83
|
+
}
|
|
84
|
+
year() {
|
|
85
|
+
var _a;
|
|
86
|
+
return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getFullYear();
|
|
87
|
+
}
|
|
88
|
+
month() {
|
|
89
|
+
return !!this._date ? this._date.getMonth() + 1 : undefined;
|
|
90
|
+
}
|
|
91
|
+
date() {
|
|
92
|
+
var _a;
|
|
93
|
+
return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getDate();
|
|
94
|
+
}
|
|
95
|
+
hour() {
|
|
96
|
+
var _a;
|
|
97
|
+
return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getHours();
|
|
98
|
+
}
|
|
99
|
+
minute() {
|
|
100
|
+
var _a;
|
|
101
|
+
return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getMinutes();
|
|
102
|
+
}
|
|
103
|
+
second() {
|
|
104
|
+
var _a;
|
|
105
|
+
return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getSeconds();
|
|
106
|
+
}
|
|
107
|
+
millisecond() {
|
|
108
|
+
var _a;
|
|
109
|
+
return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getMilliseconds();
|
|
110
|
+
}
|
|
111
|
+
day() {
|
|
112
|
+
var _a;
|
|
113
|
+
return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getDay();
|
|
114
|
+
}
|
|
115
|
+
add(amount, unit) {
|
|
116
|
+
if (!this._date) {
|
|
117
|
+
return new Timez(undefined);
|
|
118
|
+
}
|
|
119
|
+
const newDate = new Date(this._date);
|
|
120
|
+
switch (unit) {
|
|
121
|
+
case 'years':
|
|
122
|
+
newDate.setFullYear(newDate.getFullYear() + amount);
|
|
123
|
+
break;
|
|
124
|
+
case 'months':
|
|
125
|
+
newDate.setMonth(newDate.getMonth() + amount);
|
|
126
|
+
break;
|
|
127
|
+
case 'days':
|
|
128
|
+
newDate.setDate(newDate.getDate() + amount);
|
|
129
|
+
break;
|
|
130
|
+
case 'hours':
|
|
131
|
+
newDate.setHours(newDate.getHours() + amount);
|
|
132
|
+
break;
|
|
133
|
+
case 'minutes':
|
|
134
|
+
newDate.setMinutes(newDate.getMinutes() + amount);
|
|
135
|
+
break;
|
|
136
|
+
case 'seconds':
|
|
137
|
+
newDate.setSeconds(newDate.getSeconds() + amount);
|
|
138
|
+
break;
|
|
139
|
+
case 'milliseconds':
|
|
140
|
+
newDate.setMilliseconds(newDate.getMilliseconds() + amount);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
return new Timez(newDate);
|
|
144
|
+
}
|
|
145
|
+
subtract(amount, unit) {
|
|
146
|
+
return this.add(-amount, unit);
|
|
147
|
+
}
|
|
148
|
+
startOf(unit) {
|
|
149
|
+
if (!this._date) {
|
|
150
|
+
return new Timez(undefined);
|
|
151
|
+
}
|
|
152
|
+
const newDate = new Date(this._date);
|
|
153
|
+
switch (unit) {
|
|
154
|
+
case 'year':
|
|
155
|
+
newDate.setMonth(0, 1);
|
|
156
|
+
newDate.setHours(0, 0, 0, 0);
|
|
157
|
+
break;
|
|
158
|
+
case 'month':
|
|
159
|
+
newDate.setDate(1);
|
|
160
|
+
newDate.setHours(0, 0, 0, 0);
|
|
161
|
+
break;
|
|
162
|
+
case 'day':
|
|
163
|
+
newDate.setHours(0, 0, 0, 0);
|
|
164
|
+
break;
|
|
165
|
+
case 'hour':
|
|
166
|
+
newDate.setMinutes(0, 0, 0);
|
|
167
|
+
break;
|
|
168
|
+
case 'minute':
|
|
169
|
+
newDate.setSeconds(0, 0);
|
|
170
|
+
break;
|
|
171
|
+
case 'second':
|
|
172
|
+
newDate.setMilliseconds(0);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
return new Timez(newDate);
|
|
176
|
+
}
|
|
177
|
+
endOf(unit) {
|
|
178
|
+
const start = this.startOf(unit);
|
|
179
|
+
switch (unit) {
|
|
180
|
+
case 'year':
|
|
181
|
+
return start.add(1, 'years').subtract(1, 'milliseconds');
|
|
182
|
+
case 'month':
|
|
183
|
+
return start.add(1, 'months').subtract(1, 'milliseconds');
|
|
184
|
+
case 'day':
|
|
185
|
+
return start.add(1, 'days').subtract(1, 'milliseconds');
|
|
186
|
+
case 'hour':
|
|
187
|
+
return start.add(1, 'hours').subtract(1, 'milliseconds');
|
|
188
|
+
case 'minute':
|
|
189
|
+
return start.add(1, 'minutes').subtract(1, 'milliseconds');
|
|
190
|
+
case 'second':
|
|
191
|
+
return start.add(1, 'seconds').subtract(1, 'milliseconds');
|
|
192
|
+
default:
|
|
193
|
+
return start;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
isBefore(other, inclusivity = '()') {
|
|
197
|
+
const isIncluded = inclusivity[1] === ']';
|
|
198
|
+
const otherTimez = other instanceof Timez ? other : new Timez(other);
|
|
199
|
+
if (!this._date || !otherTimez._date) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
return ((!isIncluded &&
|
|
203
|
+
this._date < otherTimez._date) ||
|
|
204
|
+
(!!isIncluded &&
|
|
205
|
+
this._date <= otherTimez._date));
|
|
206
|
+
}
|
|
207
|
+
isAfter(other, inclusivity = '()') {
|
|
208
|
+
const isIncluded = inclusivity[0] === '[';
|
|
209
|
+
const otherTimez = other instanceof Timez ? other : new Timez(other);
|
|
210
|
+
if (!this._date || !otherTimez._date) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
return ((!isIncluded &&
|
|
214
|
+
this._date > otherTimez._date) ||
|
|
215
|
+
(!!isIncluded &&
|
|
216
|
+
this._date >= otherTimez._date));
|
|
217
|
+
}
|
|
218
|
+
isSame(other, unit) {
|
|
219
|
+
const otherTimez = other instanceof Timez ? other : new Timez(other);
|
|
220
|
+
if (!unit && this._date && otherTimez._date) {
|
|
221
|
+
return this._date.getTime() === otherTimez._date.getTime();
|
|
222
|
+
}
|
|
223
|
+
const thisStart = !!unit ? this.startOf(unit) : undefined;
|
|
224
|
+
const otherStart = !!unit ? otherTimez.startOf(unit) : undefined;
|
|
225
|
+
if (!thisStart || !(thisStart === null || thisStart === void 0 ? void 0 : thisStart._date) || !otherStart || !(otherStart === null || otherStart === void 0 ? void 0 : otherStart._date)) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
return thisStart._date.getTime() === otherStart._date.getTime();
|
|
229
|
+
}
|
|
230
|
+
isBetween(start, end, inclusivity = '()') {
|
|
231
|
+
const startTimez = start instanceof Timez ? start : new Timez(start);
|
|
232
|
+
const endTimez = end instanceof Timez ? end : new Timez(end);
|
|
233
|
+
const startIncluded = inclusivity[0] === '[';
|
|
234
|
+
const endIncluded = inclusivity[1] === ']';
|
|
235
|
+
const afterStart = startIncluded ?
|
|
236
|
+
this.isSame(startTimez) || this.isAfter(startTimez) :
|
|
237
|
+
this.isAfter(startTimez);
|
|
238
|
+
const beforeEnd = endIncluded ?
|
|
239
|
+
this.isSame(endTimez) || this.isBefore(endTimez) :
|
|
240
|
+
this.isBefore(endTimez);
|
|
241
|
+
return afterStart && beforeEnd;
|
|
242
|
+
}
|
|
243
|
+
format(formatString) {
|
|
244
|
+
if (!formatString) {
|
|
245
|
+
return this.toISOString();
|
|
246
|
+
}
|
|
247
|
+
const predefinedFormat = Timez.PREDEFINED_FORMATS[formatString];
|
|
248
|
+
if (predefinedFormat) {
|
|
249
|
+
return this.format(predefinedFormat);
|
|
250
|
+
}
|
|
251
|
+
let result = '';
|
|
252
|
+
let i = 0;
|
|
253
|
+
while (i < formatString.length) {
|
|
254
|
+
if (formatString[i] === '[') {
|
|
255
|
+
const endIndex = formatString.indexOf(']', i);
|
|
256
|
+
if (endIndex === -1) {
|
|
257
|
+
result += formatString[i];
|
|
258
|
+
i++;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
const literal = formatString.substring(i + 1, endIndex);
|
|
262
|
+
result += literal;
|
|
263
|
+
i = endIndex + 1;
|
|
264
|
+
}
|
|
265
|
+
else if (formatString[i] === '%' && i + 1 < formatString.length) {
|
|
266
|
+
const token = `%${formatString[i + 1]}`;
|
|
267
|
+
const formatter = Timez.FORMAT_TOKENS[token];
|
|
268
|
+
if (formatter) {
|
|
269
|
+
result += formatter(this);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
result += token;
|
|
273
|
+
}
|
|
274
|
+
i += 2;
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
result += formatString[i];
|
|
278
|
+
i++;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
setTimezone(timezone) {
|
|
284
|
+
if (!this._date) {
|
|
285
|
+
return new Timez(undefined);
|
|
286
|
+
}
|
|
287
|
+
const currentOffset = this._date.getTimezoneOffset();
|
|
288
|
+
const targetOffset = this.parseTimezoneOffset(timezone);
|
|
289
|
+
const adjustedDate = new Date(this._date.getTime() + (targetOffset - currentOffset) * 60000);
|
|
290
|
+
return new Timez(adjustedDate);
|
|
291
|
+
}
|
|
292
|
+
utc() {
|
|
293
|
+
if (!this._date) {
|
|
294
|
+
return new Timez(undefined);
|
|
295
|
+
}
|
|
296
|
+
return new Timez(new Date(Date.UTC(this._date.getUTCFullYear(), this._date.getUTCMonth(), this._date.getUTCDate(), this._date.getUTCHours(), this._date.getUTCMinutes(), this._date.getUTCSeconds(), this._date.getUTCMilliseconds())));
|
|
297
|
+
}
|
|
298
|
+
local() {
|
|
299
|
+
if (!this._date) {
|
|
300
|
+
return new Timez(undefined);
|
|
301
|
+
}
|
|
302
|
+
return new Timez(new Date(this._date.getFullYear(), this._date.getMonth(), this._date.getDate(), this._date.getHours(), this._date.getMinutes(), this._date.getSeconds(), this._date.getMilliseconds()));
|
|
303
|
+
}
|
|
304
|
+
toString() {
|
|
305
|
+
var _a;
|
|
306
|
+
return (_a = this._date) === null || _a === void 0 ? void 0 : _a.toString();
|
|
307
|
+
}
|
|
308
|
+
toISOString() {
|
|
309
|
+
var _a;
|
|
310
|
+
return (_a = this._date) === null || _a === void 0 ? void 0 : _a.toISOString();
|
|
311
|
+
}
|
|
312
|
+
toDate() {
|
|
313
|
+
return !!this._date ? new Date(this._date) : undefined;
|
|
314
|
+
}
|
|
315
|
+
valueOf() {
|
|
316
|
+
var _a;
|
|
317
|
+
return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getTime();
|
|
318
|
+
}
|
|
319
|
+
unix() {
|
|
320
|
+
return !!this._date ? Math.floor(this._date.getTime() / 1000) : undefined;
|
|
321
|
+
}
|
|
322
|
+
utcOffset() {
|
|
323
|
+
return this._date ? -this._date.getTimezoneOffset() : undefined;
|
|
324
|
+
}
|
|
325
|
+
isCorrect() {
|
|
326
|
+
return !!this._date && !isNaN(this._date.getTime());
|
|
327
|
+
}
|
|
328
|
+
timezone() {
|
|
329
|
+
if (!this._date)
|
|
330
|
+
return undefined;
|
|
331
|
+
try {
|
|
332
|
+
const formatter = new Intl.DateTimeFormat();
|
|
333
|
+
const timezone = formatter.resolvedOptions().timeZone;
|
|
334
|
+
return timezone || undefined;
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
return this.timezoneFromOffset();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
timezoneAbbr() {
|
|
341
|
+
if (!this._date)
|
|
342
|
+
return undefined;
|
|
343
|
+
try {
|
|
344
|
+
const formatter = new Intl.DateTimeFormat('en', {
|
|
345
|
+
timeZoneName: 'short'
|
|
346
|
+
});
|
|
347
|
+
const parts = formatter.formatToParts(this._date);
|
|
348
|
+
const timezonePart = parts.find(part => part.type === 'timeZoneName');
|
|
349
|
+
return (timezonePart === null || timezonePart === void 0 ? void 0 : timezonePart.value) || undefined;
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
return this.timezoneAbbrFromOffset();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
timezoneName() {
|
|
356
|
+
if (!this._date)
|
|
357
|
+
return undefined;
|
|
358
|
+
try {
|
|
359
|
+
const formatter = new Intl.DateTimeFormat('en', {
|
|
360
|
+
timeZoneName: 'long'
|
|
361
|
+
});
|
|
362
|
+
const parts = formatter.formatToParts(this._date);
|
|
363
|
+
const timezonePart = parts.find(part => part.type === 'timeZoneName');
|
|
364
|
+
return (timezonePart === null || timezonePart === void 0 ? void 0 : timezonePart.value) || undefined;
|
|
365
|
+
}
|
|
366
|
+
catch (error) {
|
|
367
|
+
return this.timezoneNameFromOffset();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
timezoneOffsetString() {
|
|
371
|
+
const offset = this.utcOffset();
|
|
372
|
+
if (offset === undefined)
|
|
373
|
+
return undefined;
|
|
374
|
+
const sign = offset >= 0 ? '+' : '-';
|
|
375
|
+
const hours = Math.floor(Math.abs(offset) / 60).toString().padStart(2, '0');
|
|
376
|
+
const minutes = (Math.abs(offset) % 60).toString().padStart(2, '0');
|
|
377
|
+
return `${sign}${hours}:${minutes}`;
|
|
378
|
+
}
|
|
379
|
+
dateChecker(input) {
|
|
380
|
+
return ((input instanceof Timez &&
|
|
381
|
+
!!input &&
|
|
382
|
+
!!(input === null || input === void 0 ? void 0 : input._date)) ||
|
|
383
|
+
input instanceof Date ||
|
|
384
|
+
typeof input === 'string' ||
|
|
385
|
+
typeof input === 'number' || (input === undefined ||
|
|
386
|
+
input === null ||
|
|
387
|
+
(typeof input === 'number' && isNaN(input))));
|
|
388
|
+
}
|
|
389
|
+
timezoneFromOffset() {
|
|
390
|
+
const offset = this.utcOffset();
|
|
391
|
+
if (offset === undefined)
|
|
392
|
+
return undefined;
|
|
393
|
+
const offsetToTimezone = {
|
|
394
|
+
0: 'Etc/UTC',
|
|
395
|
+
60: 'Europe/Paris',
|
|
396
|
+
120: 'Europe/Athens',
|
|
397
|
+
180: 'Europe/Moscow',
|
|
398
|
+
240: 'Asia/Dubai',
|
|
399
|
+
270: 'Asia/Tehran',
|
|
400
|
+
300: 'Asia/Karachi',
|
|
401
|
+
330: 'Asia/Kolkata',
|
|
402
|
+
345: 'Asia/Rangoon',
|
|
403
|
+
360: 'Asia/Dhaka',
|
|
404
|
+
390: 'Asia/Yangon',
|
|
405
|
+
420: 'Asia/Bangkok',
|
|
406
|
+
480: 'Asia/Shanghai',
|
|
407
|
+
525: 'Asia/Kathmandu',
|
|
408
|
+
540: 'Asia/Tokyo',
|
|
409
|
+
570: 'Australia/Adelaide',
|
|
410
|
+
600: 'Australia/Sydney',
|
|
411
|
+
630: 'Australia/Lord_Howe',
|
|
412
|
+
660: 'Pacific/Noumea',
|
|
413
|
+
675: 'Australia/Eucla',
|
|
414
|
+
720: 'Pacific/Auckland',
|
|
415
|
+
780: 'Pacific/Chatham',
|
|
416
|
+
[-60]: 'Atlantic/Azores',
|
|
417
|
+
[-120]: 'America/Noronha',
|
|
418
|
+
[-180]: 'America/Argentina/Buenos_Aires',
|
|
419
|
+
[-210]: 'America/St_Johns',
|
|
420
|
+
[-240]: 'America/Halifax',
|
|
421
|
+
[-270]: 'America/Caracas',
|
|
422
|
+
[-300]: 'America/New_York',
|
|
423
|
+
[-360]: 'America/Chicago',
|
|
424
|
+
[-420]: 'America/Denver',
|
|
425
|
+
[-480]: 'America/Los_Angeles',
|
|
426
|
+
[-540]: 'America/Anchorage',
|
|
427
|
+
[-600]: 'Pacific/Honolulu',
|
|
428
|
+
[-660]: 'Pacific/Pago_Pago',
|
|
429
|
+
[-720]: 'Pacific/Kiritimati',
|
|
430
|
+
};
|
|
431
|
+
return offsetToTimezone[offset] || `Etc/GMT${offset >= 0 ? '-' : '+'}${Math.abs(offset) / 60}`;
|
|
432
|
+
}
|
|
433
|
+
timezoneAbbrFromOffset() {
|
|
434
|
+
const offset = this.utcOffset();
|
|
435
|
+
if (offset === undefined)
|
|
436
|
+
return undefined;
|
|
437
|
+
const offsetToAbbr = {
|
|
438
|
+
0: 'GMT',
|
|
439
|
+
60: 'CET',
|
|
440
|
+
[-300]: 'EST',
|
|
441
|
+
[-360]: 'CST',
|
|
442
|
+
[-420]: 'MST',
|
|
443
|
+
[-480]: 'PST',
|
|
444
|
+
};
|
|
445
|
+
return offsetToAbbr[offset] || `GMT${offset >= 0 ? '+' : ''}${offset / 60}`;
|
|
446
|
+
}
|
|
447
|
+
timezoneNameFromOffset() {
|
|
448
|
+
const offset = this.utcOffset();
|
|
449
|
+
if (offset === undefined)
|
|
450
|
+
return undefined;
|
|
451
|
+
const offsetToName = {
|
|
452
|
+
0: 'Greenwich Mean Time',
|
|
453
|
+
60: 'Central European Time',
|
|
454
|
+
[-300]: 'Eastern Standard Time',
|
|
455
|
+
[-360]: 'Central Standard Time',
|
|
456
|
+
[-420]: 'Mountain Standard Time',
|
|
457
|
+
[-480]: 'Pacific Standard Time',
|
|
458
|
+
};
|
|
459
|
+
return offsetToName[offset] || `GMT${offset >= 0 ? '+' : ''}${offset / 60}`;
|
|
460
|
+
}
|
|
461
|
+
isDST() {
|
|
462
|
+
if (!this._date)
|
|
463
|
+
return undefined;
|
|
464
|
+
try {
|
|
465
|
+
const jan = new Date(this._date.getFullYear(), 0, 1);
|
|
466
|
+
const jul = new Date(this._date.getFullYear(), 6, 1);
|
|
467
|
+
const stdOffset = Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
|
|
468
|
+
return this._date.getTimezoneOffset() < stdOffset;
|
|
469
|
+
}
|
|
470
|
+
catch (error) {
|
|
471
|
+
return undefined;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
static parseString(dateString, enableException = false) {
|
|
475
|
+
const isoDate = new Date(dateString);
|
|
476
|
+
if (!isNaN(isoDate.getTime())) {
|
|
477
|
+
return isoDate;
|
|
478
|
+
}
|
|
479
|
+
const formats = [
|
|
480
|
+
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})Z$/,
|
|
481
|
+
/^(\d{4})-(\d{2})-(\d{2})$/,
|
|
482
|
+
/^(\d{4})\/(\d{2})\/(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,
|
|
483
|
+
/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/
|
|
484
|
+
];
|
|
485
|
+
for (const regex of formats) {
|
|
486
|
+
const match = dateString.match(regex);
|
|
487
|
+
if (match) {
|
|
488
|
+
const components = match.slice(1).map(Number);
|
|
489
|
+
if (regex === formats[0]) {
|
|
490
|
+
return new Date(Date.UTC(components[0], components[1] - 1, components[2], components[3], components[4], components[5], components[6]));
|
|
491
|
+
}
|
|
492
|
+
else if (regex === formats[1]) {
|
|
493
|
+
return new Date(components[0], components[1] - 1, components[2]);
|
|
494
|
+
}
|
|
495
|
+
else if (regex === formats[2]) {
|
|
496
|
+
return new Date(components[0], components[1] - 1, components[2], components[3], components[4], components[5]);
|
|
497
|
+
}
|
|
498
|
+
else if (regex === formats[3]) {
|
|
499
|
+
return new Date(components[0], components[1] - 1, components[2], components[3], components[4], components[5]);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
const fallback = new Date(dateString);
|
|
504
|
+
if (!isNaN(fallback.getTime())) {
|
|
505
|
+
return fallback;
|
|
506
|
+
}
|
|
507
|
+
if (!!enableException) {
|
|
508
|
+
throw new Error(`Unable to parse date string: ${dateString}`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
static parseWithFormat(value, format) {
|
|
512
|
+
if (!value || !format)
|
|
513
|
+
return undefined;
|
|
514
|
+
const valueStr = String(value).trim();
|
|
515
|
+
if (!valueStr)
|
|
516
|
+
return undefined;
|
|
517
|
+
const tokenHandlers = {
|
|
518
|
+
'Y': {
|
|
519
|
+
regex: /\d{4}/,
|
|
520
|
+
extract: (match) => parseInt(match, 10)
|
|
521
|
+
},
|
|
522
|
+
'y': {
|
|
523
|
+
regex: /\d{2}/,
|
|
524
|
+
extract: (match) => {
|
|
525
|
+
const year = parseInt(match, 10);
|
|
526
|
+
return year >= 70 ? 1900 + year : 2000 + year;
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
'm': {
|
|
530
|
+
regex: /\d{1,2}/,
|
|
531
|
+
extract: (match) => parseInt(match, 10)
|
|
532
|
+
},
|
|
533
|
+
'd': {
|
|
534
|
+
regex: /\d{1,2}/,
|
|
535
|
+
extract: (match) => parseInt(match, 10)
|
|
536
|
+
},
|
|
537
|
+
'H': {
|
|
538
|
+
regex: /\d{1,2}/,
|
|
539
|
+
extract: (match) => parseInt(match, 10)
|
|
540
|
+
},
|
|
541
|
+
'M': {
|
|
542
|
+
regex: /\d{1,2}/,
|
|
543
|
+
extract: (match) => parseInt(match, 10)
|
|
544
|
+
},
|
|
545
|
+
'S': {
|
|
546
|
+
regex: /\d{1,2}/,
|
|
547
|
+
extract: (match) => parseInt(match, 10)
|
|
548
|
+
},
|
|
549
|
+
'f': {
|
|
550
|
+
regex: /\d{1,3}/,
|
|
551
|
+
extract: (match) => parseInt(match, 10)
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
const result = {
|
|
555
|
+
year: new Date().getFullYear(),
|
|
556
|
+
month: 1,
|
|
557
|
+
day: 1,
|
|
558
|
+
hour: 0,
|
|
559
|
+
minute: 0,
|
|
560
|
+
second: 0,
|
|
561
|
+
millisecond: 0
|
|
562
|
+
};
|
|
563
|
+
let valueIndex = 0;
|
|
564
|
+
let formatIndex = 0;
|
|
565
|
+
let inLiteral = false;
|
|
566
|
+
let currentLiteral = '';
|
|
567
|
+
while (formatIndex < format.length && valueIndex < valueStr.length) {
|
|
568
|
+
const formatChar = format[formatIndex];
|
|
569
|
+
if (formatChar === '[') {
|
|
570
|
+
inLiteral = true;
|
|
571
|
+
currentLiteral = '';
|
|
572
|
+
formatIndex++;
|
|
573
|
+
}
|
|
574
|
+
else if (formatChar === ']' && inLiteral) {
|
|
575
|
+
if (valueStr.substring(valueIndex, valueIndex + currentLiteral.length) === currentLiteral) {
|
|
576
|
+
valueIndex += currentLiteral.length;
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
return undefined;
|
|
580
|
+
}
|
|
581
|
+
inLiteral = false;
|
|
582
|
+
currentLiteral = '';
|
|
583
|
+
formatIndex++;
|
|
584
|
+
}
|
|
585
|
+
else if (inLiteral) {
|
|
586
|
+
currentLiteral += formatChar;
|
|
587
|
+
formatIndex++;
|
|
588
|
+
}
|
|
589
|
+
else if (formatChar === '%' && formatIndex + 1 < format.length) {
|
|
590
|
+
const token = format[formatIndex + 1];
|
|
591
|
+
const handler = tokenHandlers[token];
|
|
592
|
+
if (handler) {
|
|
593
|
+
const remainingValue = valueStr.substring(valueIndex);
|
|
594
|
+
const match = remainingValue.match(handler.regex);
|
|
595
|
+
if (match && match.index === 0) {
|
|
596
|
+
const matchedValue = match[0];
|
|
597
|
+
const numericValue = handler.extract(matchedValue);
|
|
598
|
+
switch (token) {
|
|
599
|
+
case 'Y':
|
|
600
|
+
case 'y':
|
|
601
|
+
result.year = numericValue;
|
|
602
|
+
break;
|
|
603
|
+
case 'm':
|
|
604
|
+
result.month = numericValue;
|
|
605
|
+
break;
|
|
606
|
+
case 'd':
|
|
607
|
+
result.day = numericValue;
|
|
608
|
+
break;
|
|
609
|
+
case 'H':
|
|
610
|
+
result.hour = numericValue;
|
|
611
|
+
break;
|
|
612
|
+
case 'M':
|
|
613
|
+
result.minute = numericValue;
|
|
614
|
+
break;
|
|
615
|
+
case 'S':
|
|
616
|
+
result.second = numericValue;
|
|
617
|
+
break;
|
|
618
|
+
case 'f':
|
|
619
|
+
result.millisecond = numericValue;
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
valueIndex += matchedValue.length;
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
return undefined;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
valueIndex++;
|
|
630
|
+
}
|
|
631
|
+
formatIndex += 2;
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
if (formatChar === valueStr[valueIndex]) {
|
|
635
|
+
valueIndex++;
|
|
636
|
+
formatIndex++;
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
return undefined;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
if (result.month < 1 || result.month > 12)
|
|
644
|
+
return undefined;
|
|
645
|
+
if (result.day < 1 || result.day > 31)
|
|
646
|
+
return undefined;
|
|
647
|
+
if (result.hour < 0 || result.hour > 23)
|
|
648
|
+
return undefined;
|
|
649
|
+
if (result.minute < 0 || result.minute > 59)
|
|
650
|
+
return undefined;
|
|
651
|
+
if (result.second < 0 || result.second > 59)
|
|
652
|
+
return undefined;
|
|
653
|
+
if (result.millisecond < 0 || result.millisecond > 999)
|
|
654
|
+
return undefined;
|
|
655
|
+
try {
|
|
656
|
+
const date = new Date(result.year, result.month - 1,
|
|
657
|
+
result.day, result.hour, result.minute, result.second, result.millisecond);
|
|
658
|
+
if (isNaN(date.getTime())) {
|
|
659
|
+
return undefined;
|
|
660
|
+
}
|
|
661
|
+
return new Timez(date);
|
|
662
|
+
}
|
|
663
|
+
catch (error) {
|
|
664
|
+
return undefined;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
static getTokenLength(token) {
|
|
668
|
+
const tokenLengths = {
|
|
669
|
+
'Y': 4,
|
|
670
|
+
'y': 2,
|
|
671
|
+
'm': 2,
|
|
672
|
+
'd': 2,
|
|
673
|
+
'H': 2,
|
|
674
|
+
'M': 2,
|
|
675
|
+
'S': 2,
|
|
676
|
+
'f': 3,
|
|
677
|
+
'z': 5
|
|
678
|
+
};
|
|
679
|
+
return tokenLengths[token] || 1;
|
|
680
|
+
}
|
|
681
|
+
parseTimezoneOffset(timezone) {
|
|
682
|
+
const offsets = {
|
|
683
|
+
'UTC': 0,
|
|
684
|
+
'EST': -300,
|
|
685
|
+
'EDT': -240,
|
|
686
|
+
'CST': -360,
|
|
687
|
+
'CDT': -300,
|
|
688
|
+
'PST': -480,
|
|
689
|
+
'PDT': -420,
|
|
690
|
+
};
|
|
691
|
+
if (offsets[timezone.toUpperCase()] !== undefined) {
|
|
692
|
+
return offsets[timezone.toUpperCase()];
|
|
693
|
+
}
|
|
694
|
+
const match = timezone.match(/^([+-])(\d{1,2}):?(\d{2})?$/);
|
|
695
|
+
if (match) {
|
|
696
|
+
const sign = match[1] === '+' ? 1 : -1;
|
|
697
|
+
const hours = parseInt(match[2], 10);
|
|
698
|
+
const minutes = match[3] ? parseInt(match[3], 10) : 0;
|
|
699
|
+
return sign * (hours * 60 + minutes);
|
|
700
|
+
}
|
|
701
|
+
return this._date ? -this._date.getTimezoneOffset() : 0;
|
|
702
|
+
}
|
|
703
|
+
static get FORMATS() {
|
|
704
|
+
return Object.assign({}, Timez.PREDEFINED_FORMATS);
|
|
705
|
+
}
|
|
706
|
+
static exposeToGlobal() {
|
|
707
|
+
if (typeof window !== 'undefined') {
|
|
708
|
+
window.Timez = Timez;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
Timez.FORMAT_TOKENS = {
|
|
713
|
+
'%Y': (t) => { var _a; return (_a = t.year()) === null || _a === void 0 ? void 0 : _a.toString().padStart(4, '0'); },
|
|
714
|
+
'%y': (t) => { var _a; return (_a = t.year()) === null || _a === void 0 ? void 0 : _a.toString().slice(-2).padStart(2, '0'); },
|
|
715
|
+
'%m': (t) => { var _a; return (_a = t.month()) === null || _a === void 0 ? void 0 : _a.toString().padStart(2, '0'); },
|
|
716
|
+
'%d': (t) => { var _a; return (_a = t.date()) === null || _a === void 0 ? void 0 : _a.toString().padStart(2, '0'); },
|
|
717
|
+
'%H': (t) => { var _a; return (_a = t.hour()) === null || _a === void 0 ? void 0 : _a.toString().padStart(2, '0'); },
|
|
718
|
+
'%M': (t) => { var _a; return (_a = t.minute()) === null || _a === void 0 ? void 0 : _a.toString().padStart(2, '0'); },
|
|
719
|
+
'%S': (t) => { var _a; return (_a = t.second()) === null || _a === void 0 ? void 0 : _a.toString().padStart(2, '0'); },
|
|
720
|
+
'%f': (t) => { var _a; return (_a = t.millisecond()) === null || _a === void 0 ? void 0 : _a.toString().padStart(3, '0'); },
|
|
721
|
+
'%z': (t) => {
|
|
722
|
+
const offset = t.utcOffset();
|
|
723
|
+
if (!offset) {
|
|
724
|
+
return undefined;
|
|
725
|
+
}
|
|
726
|
+
const sign = offset >= 0 ? '+' : '-';
|
|
727
|
+
const hours = Math.floor(Math.abs(offset) / 60).toString().padStart(2, '0');
|
|
728
|
+
const minutes = (Math.abs(offset) % 60).toString().padStart(2, '0');
|
|
729
|
+
return `${sign}${hours}${minutes}`;
|
|
730
|
+
},
|
|
731
|
+
'%s': (t) => {
|
|
732
|
+
const val = t.valueOf();
|
|
733
|
+
return !!val ? Math.floor(val / 1000).toString() : undefined;
|
|
734
|
+
},
|
|
735
|
+
};
|
|
736
|
+
Timez.PREDEFINED_FORMATS = {
|
|
737
|
+
ISO: '%Y-%m-%dT%H:%M:%S.%fZ',
|
|
738
|
+
ISO_DATE: '%Y-%m-%d',
|
|
739
|
+
ISO_TIME: '%H:%M:%S.%fZ',
|
|
740
|
+
COMPACT: '%Y%m%d%H%M%S',
|
|
741
|
+
SLASH_DATETIME: '%Y/%m/%d %H:%M:%S.%fZ',
|
|
742
|
+
SLASH_DATETIME_SEC: '%Y/%m/%d %H:%M:%S',
|
|
743
|
+
SLASH_DATETIME_MIN: '%Y/%m/%d %H:%M',
|
|
744
|
+
EUROPEAN: '%d/%m/%Y %H:%M:%S GMT%z',
|
|
745
|
+
SLASH_DATE: '%Y/%m/%d',
|
|
746
|
+
TIME_MICRO: '%H:%M:%S.%fZ',
|
|
747
|
+
TIME_SEC: '%H:%M:%S',
|
|
748
|
+
CUSTOM_GREETING: '[Bonjour celestin, ][la date actuelle est:: le] %d/%m/%Y [à] %H:%M:%S.%f[Z]',
|
|
749
|
+
};
|
|
750
|
+
if (typeof window !== 'undefined') {
|
|
751
|
+
window.Timez = Timez;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
timez.Timez = Timez;
|
|
755
|
+
timez.default = Timez;
|
|
756
|
+
return timez;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
var hasRequiredCooks;
|
|
760
|
+
|
|
761
|
+
function requireCooks () {
|
|
762
|
+
if (hasRequiredCooks) return cooks;
|
|
763
|
+
hasRequiredCooks = 1;
|
|
764
|
+
|
|
765
|
+
Object.defineProperty(cooks, '__esModule', { value: true });
|
|
766
|
+
|
|
767
|
+
var timez = requireTimez();
|
|
768
|
+
|
|
769
|
+
const tabAlphabetique = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
|
|
770
|
+
[...tabAlphabetique, ...tabAlphabetique.map(x => x.toUpperCase())];
|
|
771
|
+
|
|
772
|
+
class Cooks {
|
|
773
|
+
static set(key, value, options = {}) {
|
|
774
|
+
if (!this.isBrowser())
|
|
775
|
+
return;
|
|
776
|
+
try {
|
|
777
|
+
const serializedValue = this.serialize(value);
|
|
778
|
+
const encodedValue = encodeURIComponent(serializedValue);
|
|
779
|
+
const cookieString = this.buildCookieString(key, encodedValue, options);
|
|
780
|
+
document.cookie = cookieString;
|
|
781
|
+
}
|
|
782
|
+
catch (error) {
|
|
783
|
+
console.error(`Cooks: Error setting cookie "${key}":`, error);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
static get(key) {
|
|
787
|
+
if (!this.isBrowser())
|
|
788
|
+
return null;
|
|
789
|
+
try {
|
|
790
|
+
const cookies = this.getAllCookies();
|
|
791
|
+
const encodedValue = cookies[key];
|
|
792
|
+
if (!encodedValue)
|
|
793
|
+
return null;
|
|
794
|
+
const decodedValue = decodeURIComponent(encodedValue);
|
|
795
|
+
return this.deserialize(decodedValue);
|
|
796
|
+
}
|
|
797
|
+
catch (error) {
|
|
798
|
+
console.error(`Cooks: Error getting cookie "${key}":`, error);
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
static remove(key, path = '/', domain) {
|
|
803
|
+
if (!this.isBrowser())
|
|
804
|
+
return;
|
|
805
|
+
const options = {
|
|
806
|
+
expires: new Date(0),
|
|
807
|
+
path,
|
|
808
|
+
domain
|
|
809
|
+
};
|
|
810
|
+
this.set(key, '', options);
|
|
811
|
+
}
|
|
812
|
+
static has(key) {
|
|
813
|
+
return this.get(key) !== null;
|
|
814
|
+
}
|
|
815
|
+
static keys() {
|
|
816
|
+
if (!this.isBrowser())
|
|
817
|
+
return [];
|
|
818
|
+
const cookies = this.getAllCookies();
|
|
819
|
+
return Object.keys(cookies);
|
|
820
|
+
}
|
|
821
|
+
static clear() {
|
|
822
|
+
if (!this.isBrowser())
|
|
823
|
+
return;
|
|
824
|
+
const cookies = this.getAllCookies();
|
|
825
|
+
Object.keys(cookies).forEach(key => {
|
|
826
|
+
this.remove(key);
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
static serialize(value) {
|
|
830
|
+
if (value instanceof Date) {
|
|
831
|
+
return JSON.stringify({
|
|
832
|
+
__type: 'Date',
|
|
833
|
+
__value: value.toISOString()
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
return JSON.stringify(value);
|
|
837
|
+
}
|
|
838
|
+
static deserialize(value) {
|
|
839
|
+
const parsed = JSON.parse(value);
|
|
840
|
+
if (parsed && typeof parsed === 'object' && parsed.__type === 'Date') {
|
|
841
|
+
return new Date(parsed.__value);
|
|
842
|
+
}
|
|
843
|
+
return parsed;
|
|
844
|
+
}
|
|
845
|
+
static buildCookieString(key, value, options) {
|
|
846
|
+
const mergedOptions = Object.assign(Object.assign({}, this.DEFAULT_OPTIONS), options);
|
|
847
|
+
let cookieString = `${key}=${value}`;
|
|
848
|
+
if (mergedOptions.expires !== undefined) {
|
|
849
|
+
let expirationDate;
|
|
850
|
+
if (typeof mergedOptions.expires === 'number') {
|
|
851
|
+
const expirationDateInitial = new timez.Timez().add(mergedOptions.expires, 'seconds').toDate();
|
|
852
|
+
if (!!expirationDateInitial) {
|
|
853
|
+
expirationDate = expirationDateInitial;
|
|
854
|
+
}
|
|
855
|
+
else {
|
|
856
|
+
expirationDate = new Date();
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
else {
|
|
860
|
+
expirationDate = mergedOptions.expires;
|
|
861
|
+
}
|
|
862
|
+
cookieString += `; expires=${expirationDate.toUTCString()}`;
|
|
863
|
+
}
|
|
864
|
+
if (mergedOptions.path)
|
|
865
|
+
cookieString += `; path=${mergedOptions.path}`;
|
|
866
|
+
if (mergedOptions.domain)
|
|
867
|
+
cookieString += `; domain=${mergedOptions.domain}`;
|
|
868
|
+
if (mergedOptions.secure)
|
|
869
|
+
cookieString += `; secure`;
|
|
870
|
+
if (mergedOptions.sameSite)
|
|
871
|
+
cookieString += `; samesite=${mergedOptions.sameSite}`;
|
|
872
|
+
{
|
|
873
|
+
console.log(`Cooks - buildCookieString | cookieString:: `, cookieString);
|
|
874
|
+
}
|
|
875
|
+
return cookieString;
|
|
876
|
+
}
|
|
877
|
+
static getAllCookies() {
|
|
878
|
+
return document.cookie
|
|
879
|
+
.split(';')
|
|
880
|
+
.reduce((cookies, cookie) => {
|
|
881
|
+
const [key, value] = cookie.split('=').map(part => part.trim());
|
|
882
|
+
if (key) {
|
|
883
|
+
cookies[key] = value || '';
|
|
884
|
+
}
|
|
885
|
+
return cookies;
|
|
886
|
+
}, {});
|
|
887
|
+
}
|
|
888
|
+
static isBrowser() {
|
|
889
|
+
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
890
|
+
}
|
|
891
|
+
static exposeToGlobal() {
|
|
892
|
+
if (typeof window !== "undefined") {
|
|
893
|
+
window.Cooks = Cooks;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
Cooks.DEFAULT_OPTIONS = {
|
|
898
|
+
path: '/',
|
|
899
|
+
secure: true,
|
|
900
|
+
sameSite: 'lax'
|
|
901
|
+
};
|
|
902
|
+
if (typeof window !== "undefined") {
|
|
903
|
+
window.Cooks = Cooks;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
cooks.Cooks = Cooks;
|
|
907
|
+
cooks.default = Cooks;
|
|
908
|
+
return cooks;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
requireCooks();
|
|
912
|
+
|
|
913
|
+
const DEFAULT_SCOPE = 'app';
|
|
914
|
+
|
|
20
915
|
const mergeDeep = (target, source) => {
|
|
21
916
|
if (typeof target !== 'object' || typeof source !== 'object')
|
|
22
917
|
return source;
|
|
@@ -34,42 +929,47 @@ const mergeDeep = (target, source) => {
|
|
|
34
929
|
return output;
|
|
35
930
|
};
|
|
36
931
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
932
|
+
const loadBaseConfig = (scope, configManagerConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
933
|
+
if (!(configManagerConfig === null || configManagerConfig === void 0 ? void 0 : configManagerConfig.base[scope])) {
|
|
934
|
+
console.warn(`❌ No base config found for scope: ${scope}`);
|
|
935
|
+
console.warn('Available scopes:', (configManagerConfig === null || configManagerConfig === void 0 ? void 0 : configManagerConfig.base) ? Object.keys(configManagerConfig.base) : 'none');
|
|
936
|
+
return {};
|
|
937
|
+
}
|
|
40
938
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
const baseConfigs = yield Promise.all(Object.entries(configManagerConfig.base).map((_a) => __awaiter(void 0, [_a], void 0, function* ([key, loader]) {
|
|
46
|
-
try {
|
|
47
|
-
const config = yield loader();
|
|
48
|
-
return { key, config };
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
console.error(`Failed to load base config ${key}:`, error);
|
|
52
|
-
return { key, config: {} };
|
|
53
|
-
}
|
|
54
|
-
})));
|
|
55
|
-
return baseConfigs.reduce((acc, { key, config }) => {
|
|
56
|
-
return Object.assign(Object.assign({}, acc), config);
|
|
57
|
-
}, {});
|
|
939
|
+
const loader = configManagerConfig.base[scope];
|
|
940
|
+
const result = yield loader();
|
|
941
|
+
return result;
|
|
58
942
|
}
|
|
59
943
|
catch (error) {
|
|
60
|
-
console.error(
|
|
944
|
+
console.error(`❌ Failed to load base ${scope} config`, error);
|
|
61
945
|
return {};
|
|
62
946
|
}
|
|
63
947
|
});
|
|
64
|
-
const
|
|
948
|
+
const loadModulesConfig = (configManagerConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
949
|
const results = [];
|
|
66
|
-
{
|
|
950
|
+
if (!(configManagerConfig === null || configManagerConfig === void 0 ? void 0 : configManagerConfig.modules)) {
|
|
951
|
+
console.warn(`⚠️ No modules configuration found`);
|
|
67
952
|
return results;
|
|
68
953
|
}
|
|
954
|
+
for (const [moduleName, moduleLoader] of Object.entries(configManagerConfig.modules)) {
|
|
955
|
+
try {
|
|
956
|
+
const config = yield moduleLoader();
|
|
957
|
+
results.push({
|
|
958
|
+
moduleName,
|
|
959
|
+
config
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
catch (error) {
|
|
963
|
+
console.error(`❌ Failed to load config for module "${moduleName}"`, error);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
return results;
|
|
69
967
|
});
|
|
70
|
-
const loadModuleConfig = (moduleName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
968
|
+
const loadModuleConfig = (moduleName, configManagerConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
969
|
var _a;
|
|
72
|
-
if (!((_a = void 0 ) === null || _a === void 0 ? void 0 : _a[moduleName])) {
|
|
970
|
+
if (!((_a = configManagerConfig === null || configManagerConfig === void 0 ? void 0 : configManagerConfig.modules) === null || _a === void 0 ? void 0 : _a[moduleName])) {
|
|
971
|
+
console.warn(`❌ No config found for module "${moduleName}"`);
|
|
972
|
+
console.warn('Available modules:', (configManagerConfig === null || configManagerConfig === void 0 ? void 0 : configManagerConfig.modules) ? Object.keys(configManagerConfig.modules) : 'none');
|
|
73
973
|
return undefined;
|
|
74
974
|
}
|
|
75
975
|
try {
|
|
@@ -81,70 +981,134 @@ const loadModuleConfig = (moduleName) => __awaiter(void 0, void 0, void 0, funct
|
|
|
81
981
|
};
|
|
82
982
|
}
|
|
83
983
|
catch (error) {
|
|
84
|
-
console.error(
|
|
984
|
+
console.error(`❌ Failed to load config for module "${moduleName}"`, error);
|
|
85
985
|
return undefined;
|
|
86
986
|
}
|
|
87
987
|
});
|
|
88
988
|
|
|
89
989
|
class ConfigService {
|
|
90
|
-
constructor() {
|
|
91
|
-
Object.defineProperty(this, "
|
|
990
|
+
constructor(supportedScopes = [DEFAULT_SCOPE], configManagerConfig) {
|
|
991
|
+
Object.defineProperty(this, "configs", {
|
|
92
992
|
enumerable: true,
|
|
93
993
|
configurable: true,
|
|
94
994
|
writable: true,
|
|
95
995
|
value: {}
|
|
96
996
|
});
|
|
997
|
+
Object.defineProperty(this, "currentScope", {
|
|
998
|
+
enumerable: true,
|
|
999
|
+
configurable: true,
|
|
1000
|
+
writable: true,
|
|
1001
|
+
value: DEFAULT_SCOPE
|
|
1002
|
+
});
|
|
97
1003
|
Object.defineProperty(this, "loadedModules", {
|
|
98
1004
|
enumerable: true,
|
|
99
1005
|
configurable: true,
|
|
100
1006
|
writable: true,
|
|
101
1007
|
value: new Set()
|
|
102
1008
|
});
|
|
1009
|
+
Object.defineProperty(this, "supportedScopes", {
|
|
1010
|
+
enumerable: true,
|
|
1011
|
+
configurable: true,
|
|
1012
|
+
writable: true,
|
|
1013
|
+
value: [DEFAULT_SCOPE]
|
|
1014
|
+
});
|
|
1015
|
+
Object.defineProperty(this, "configManagerConfig", {
|
|
1016
|
+
enumerable: true,
|
|
1017
|
+
configurable: true,
|
|
1018
|
+
writable: true,
|
|
1019
|
+
value: null
|
|
1020
|
+
});
|
|
1021
|
+
this.supportedScopes = supportedScopes;
|
|
1022
|
+
if (configManagerConfig) {
|
|
1023
|
+
this.configManagerConfig = configManagerConfig;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
setConfigManagerConfig(config) {
|
|
1027
|
+
this.configManagerConfig = config;
|
|
103
1028
|
}
|
|
104
|
-
initialize() {
|
|
1029
|
+
initialize(scope) {
|
|
105
1030
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
|
|
1031
|
+
if (!this.configManagerConfig) {
|
|
1032
|
+
console.error('❌ No config manager config set in ConfigService');
|
|
1033
|
+
throw new Error('Config manager config not set');
|
|
1034
|
+
}
|
|
1035
|
+
this.currentScope = scope;
|
|
1036
|
+
yield this.loadScope(scope);
|
|
107
1037
|
});
|
|
108
1038
|
}
|
|
109
|
-
|
|
1039
|
+
loadScope(scope) {
|
|
110
1040
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
1041
|
+
if (!this.supportedScopes.includes(scope)) {
|
|
1042
|
+
console.warn(`⚠️ Scope ${scope} is not supported`);
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
if (!this.configManagerConfig) {
|
|
1046
|
+
console.error('❌ No config manager config available');
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
const base = yield loadBaseConfig(scope, this.configManagerConfig);
|
|
1050
|
+
const allModules = yield loadModulesConfig(this.configManagerConfig);
|
|
1051
|
+
this.configs[scope] = allModules.reduce((acc, { moduleName, config }) => {
|
|
114
1052
|
return mergeDeep(acc, { [moduleName]: config });
|
|
115
|
-
}, { base });
|
|
116
|
-
modules.forEach(({ moduleName }) => {
|
|
117
|
-
this.loadedModules.add(moduleName);
|
|
118
|
-
});
|
|
1053
|
+
}, { app: base });
|
|
119
1054
|
});
|
|
120
1055
|
}
|
|
121
1056
|
loadModule(moduleName) {
|
|
122
1057
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
if (this.loadedModules.has(moduleName))
|
|
1058
|
+
if (this.loadedModules.has(moduleName)) {
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
if (!this.configManagerConfig) {
|
|
1062
|
+
console.error('❌ No config manager config available');
|
|
124
1063
|
return;
|
|
125
|
-
|
|
1064
|
+
}
|
|
1065
|
+
const moduleData = yield loadModuleConfig(moduleName, this.configManagerConfig);
|
|
126
1066
|
if (moduleData === null || moduleData === void 0 ? void 0 : moduleData.config) {
|
|
127
|
-
|
|
128
|
-
|
|
1067
|
+
for (const scope of this.supportedScopes) {
|
|
1068
|
+
if (!this.configs[scope]) {
|
|
1069
|
+
this.configs[scope] = { app: {} };
|
|
1070
|
+
}
|
|
1071
|
+
this.configs[scope][moduleName] = moduleData.config;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
else {
|
|
1075
|
+
console.warn(`⚠️ No config found for module ${moduleName}`);
|
|
129
1076
|
}
|
|
1077
|
+
this.loadedModules.add(moduleName);
|
|
130
1078
|
});
|
|
131
1079
|
}
|
|
132
1080
|
get(key, options = {}) {
|
|
133
|
-
const { moduleName = '
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
1081
|
+
const { moduleName = 'app', defaultValue = undefined, } = options;
|
|
1082
|
+
const config = this.findConfig(key, moduleName) || defaultValue;
|
|
1083
|
+
return config;
|
|
1084
|
+
}
|
|
1085
|
+
findConfig(key, moduleName) {
|
|
1086
|
+
const configs = this.configs[this.currentScope];
|
|
1087
|
+
if (!configs) {
|
|
1088
|
+
console.error(`❌ No configs found for scope: ${this.currentScope}`);
|
|
1089
|
+
console.error('Available scopes:', Object.keys(this.configs));
|
|
1090
|
+
return undefined;
|
|
137
1091
|
}
|
|
138
|
-
|
|
1092
|
+
if (!configs[moduleName]) {
|
|
1093
|
+
console.error(`❌ Module "${moduleName}" not found in configs for scope ${this.currentScope}`);
|
|
1094
|
+
console.error('Available modules:', Object.keys(configs));
|
|
1095
|
+
return undefined;
|
|
1096
|
+
}
|
|
1097
|
+
const result = key.split('.').reduce((acc, part) => {
|
|
139
1098
|
return acc && acc[part] !== undefined ? acc[part] : undefined;
|
|
140
|
-
},
|
|
141
|
-
return result
|
|
1099
|
+
}, configs[moduleName]);
|
|
1100
|
+
return result;
|
|
1101
|
+
}
|
|
1102
|
+
setScope(scope) {
|
|
1103
|
+
if (this.supportedScopes.includes(scope)) {
|
|
1104
|
+
this.currentScope = scope;
|
|
1105
|
+
}
|
|
142
1106
|
}
|
|
143
|
-
|
|
144
|
-
return this.
|
|
1107
|
+
getCurrentScope() {
|
|
1108
|
+
return this.currentScope;
|
|
145
1109
|
}
|
|
146
|
-
|
|
147
|
-
return this.
|
|
1110
|
+
getAllConfigs() {
|
|
1111
|
+
return this.configs[this.currentScope] || {};
|
|
148
1112
|
}
|
|
149
1113
|
}
|
|
150
1114
|
|