@zelgadis87/utils-core 4.6.0 → 4.6.2
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/dist/Logger.d.ts +21 -0
- package/dist/Optional.d.ts +70 -0
- package/dist/async/CancelableDeferred.d.ts +17 -0
- package/dist/async/Deferred.d.ts +34 -0
- package/dist/async/RateThrottler.d.ts +13 -0
- package/dist/async/Semaphore.d.ts +17 -0
- package/dist/async/index.d.ts +4 -0
- package/dist/index.d.ts +8 -0
- package/dist/lazy/Lazy.d.ts +22 -0
- package/dist/lazy/LazyAsync.d.ts +24 -0
- package/dist/lazy/index.d.ts +2 -0
- package/dist/sorting/ComparisonChain.d.ts +57 -0
- package/dist/sorting/Sorter.d.ts +100 -0
- package/dist/sorting/index.d.ts +4 -0
- package/dist/sorting/types.d.ts +5 -0
- package/dist/time/RandomTimeDuration.d.ts +9 -0
- package/dist/time/TimeBase.d.ts +38 -0
- package/dist/time/TimeDuration.d.ts +81 -0
- package/dist/time/TimeFrequency.d.ts +10 -0
- package/dist/time/TimeInstant.d.ts +175 -0
- package/dist/time/TimeInstantBuilder.d.ts +77 -0
- package/dist/time/TimeRange.d.ts +11 -0
- package/dist/time/TimeUnit.d.ts +17 -0
- package/dist/time/index.d.ts +7 -0
- package/dist/time/types.d.ts +26 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/upgrade/DataUpgrader.d.ts +22 -0
- package/dist/upgrade/errors.d.ts +12 -0
- package/dist/upgrade/getTransitionsPath.d.ts +3 -0
- package/dist/upgrade/index.d.ts +2 -0
- package/dist/upgrade/types.d.ts +31 -0
- package/dist/utils/arrays/groupBy.d.ts +9 -0
- package/dist/utils/arrays/indexBy.d.ts +7 -0
- package/dist/utils/arrays/statistics.d.ts +8 -0
- package/dist/utils/arrays/uniqBy.d.ts +4 -0
- package/dist/utils/arrays.d.ts +57 -0
- package/dist/utils/booleans.d.ts +2 -0
- package/dist/utils/empties.d.ts +17 -0
- package/dist/utils/errors/withTryCatch.d.ts +3 -0
- package/dist/utils/errors.d.ts +3 -0
- package/dist/utils/functions/constant.d.ts +10 -0
- package/dist/utils/functions/iff.d.ts +8 -0
- package/dist/utils/functions.d.ts +31 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/json.d.ts +11 -0
- package/dist/utils/nulls.d.ts +8 -0
- package/dist/utils/numbers/round.d.ts +8 -0
- package/dist/utils/numbers.d.ts +34 -0
- package/dist/utils/primitives.d.ts +3 -0
- package/dist/utils/promises.d.ts +6 -0
- package/dist/utils/random.d.ts +7 -0
- package/dist/utils/records/entries.d.ts +4 -0
- package/dist/utils/records.d.ts +31 -0
- package/dist/utils/strings/StringParts.d.ts +32 -0
- package/dist/utils/strings.d.ts +17 -0
- package/esbuild/index.cjs +222 -93
- package/esbuild/index.cjs.map +7 -0
- package/esbuild/{index.js → index.mjs} +232 -90
- package/esbuild/index.mjs.map +7 -0
- package/package.json +3 -3
- package/esbuild/package.json +0 -39
|
@@ -1,4 +1,168 @@
|
|
|
1
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js
|
|
28
|
+
var require_format = __commonJS({
|
|
29
|
+
"../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js"(exports) {
|
|
30
|
+
"use strict";
|
|
31
|
+
Object.defineProperty(exports, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
});
|
|
34
|
+
exports["default"] = format2;
|
|
35
|
+
function ownKeys(object, enumerableOnly) {
|
|
36
|
+
var keys = Object.keys(object);
|
|
37
|
+
if (Object.getOwnPropertySymbols) {
|
|
38
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
39
|
+
if (enumerableOnly) {
|
|
40
|
+
symbols = symbols.filter(function(sym) {
|
|
41
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
keys.push.apply(keys, symbols);
|
|
45
|
+
}
|
|
46
|
+
return keys;
|
|
47
|
+
}
|
|
48
|
+
function _objectSpread(target) {
|
|
49
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
50
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
51
|
+
if (i % 2) {
|
|
52
|
+
ownKeys(Object(source), true).forEach(function(key) {
|
|
53
|
+
_defineProperty(target, key, source[key]);
|
|
54
|
+
});
|
|
55
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
|
56
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
57
|
+
} else {
|
|
58
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
59
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return target;
|
|
64
|
+
}
|
|
65
|
+
function _defineProperty(obj, key, value) {
|
|
66
|
+
if (key in obj) {
|
|
67
|
+
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
68
|
+
} else {
|
|
69
|
+
obj[key] = value;
|
|
70
|
+
}
|
|
71
|
+
return obj;
|
|
72
|
+
}
|
|
73
|
+
var PATTERN_REGEX = /(M|y|d|D|h|H|m|s|S|G|Z|P|a)+/g;
|
|
74
|
+
var ESCAPE_REGEX = /\\"|"((?:\\"|[^"])*)"|(\+)/g;
|
|
75
|
+
var optionNames = {
|
|
76
|
+
y: "year",
|
|
77
|
+
M: "month",
|
|
78
|
+
d: "day",
|
|
79
|
+
D: "weekday",
|
|
80
|
+
S: "fractionalSecondDigits",
|
|
81
|
+
G: "era",
|
|
82
|
+
Z: "timeZoneName",
|
|
83
|
+
P: "dayPeriod",
|
|
84
|
+
a: "hour12",
|
|
85
|
+
h: "hour",
|
|
86
|
+
H: "hour",
|
|
87
|
+
m: "minute",
|
|
88
|
+
s: "second"
|
|
89
|
+
};
|
|
90
|
+
var values = {
|
|
91
|
+
y: ["numeric", "2-digit", void 0, "numeric"],
|
|
92
|
+
M: ["narrow", "2-digit", "short", "long"],
|
|
93
|
+
d: ["numeric", "2-digit"],
|
|
94
|
+
D: ["narrow", "short", "long"],
|
|
95
|
+
S: [1, 2, 3],
|
|
96
|
+
G: ["narrow", "short", "long"],
|
|
97
|
+
Z: ["short", "long"],
|
|
98
|
+
P: ["narrow", "short", "long"],
|
|
99
|
+
a: [true],
|
|
100
|
+
h: ["numeric", "2-digit"],
|
|
101
|
+
H: ["numeric", "2-digit"],
|
|
102
|
+
m: ["numeric", "2-digit"],
|
|
103
|
+
s: ["numeric", "2-digit"]
|
|
104
|
+
};
|
|
105
|
+
function padIf(condition, value, length) {
|
|
106
|
+
return condition && length === 2 && value / 10 < 1 ? "0" + value : value;
|
|
107
|
+
}
|
|
108
|
+
function formatType(date, type, length) {
|
|
109
|
+
var _options;
|
|
110
|
+
var _ref = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}, locale = _ref.locale, timeZone = _ref.timeZone;
|
|
111
|
+
var option = optionNames[type];
|
|
112
|
+
var value = values[type][length - 1];
|
|
113
|
+
if (!value) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
var options = (_options = {}, _defineProperty(_options, option, value), _defineProperty(_options, "timeZone", timeZone), _options);
|
|
117
|
+
if (type === "a") {
|
|
118
|
+
return Intl.DateTimeFormat(locale, _objectSpread(_objectSpread({}, options), {}, {
|
|
119
|
+
hour: "numeric"
|
|
120
|
+
})).formatToParts(date).pop().value;
|
|
121
|
+
}
|
|
122
|
+
if (type === "G" || type === "Z") {
|
|
123
|
+
return Intl.DateTimeFormat(locale, options).formatToParts(date).pop().value;
|
|
124
|
+
}
|
|
125
|
+
if (type === "H" || type === "h") {
|
|
126
|
+
return Intl.DateTimeFormat("en-GB", _objectSpread(_objectSpread({}, options), {}, {
|
|
127
|
+
hourCycle: type === "H" ? "h23" : "h11"
|
|
128
|
+
})).format(date).toLocaleLowerCase().replace(" am", "").replace(" pm", "");
|
|
129
|
+
}
|
|
130
|
+
return padIf(["m", "s"].includes(type) && value === "2-digit", Intl.DateTimeFormat(locale, options).format(date), 2);
|
|
131
|
+
}
|
|
132
|
+
function format2(date, pattern, config) {
|
|
133
|
+
return pattern.split(ESCAPE_REGEX).filter(function(sub) {
|
|
134
|
+
return sub !== void 0;
|
|
135
|
+
}).map(function(sub, index) {
|
|
136
|
+
if (index % 2 !== 0) {
|
|
137
|
+
return sub;
|
|
138
|
+
}
|
|
139
|
+
return sub.replace(PATTERN_REGEX, function(match) {
|
|
140
|
+
var type = match.charAt(0);
|
|
141
|
+
return formatType(date, type, match.length, config) || match;
|
|
142
|
+
});
|
|
143
|
+
}).join("");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js
|
|
149
|
+
var require_lib = __commonJS({
|
|
150
|
+
"../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js"(exports) {
|
|
151
|
+
"use strict";
|
|
152
|
+
Object.defineProperty(exports, "__esModule", {
|
|
153
|
+
value: true
|
|
154
|
+
});
|
|
155
|
+
exports.format = void 0;
|
|
156
|
+
var _format = require_format();
|
|
157
|
+
var _format2 = _interopRequireDefault(_format);
|
|
158
|
+
function _interopRequireDefault(obj) {
|
|
159
|
+
return obj && obj.__esModule ? obj : { "default": obj };
|
|
160
|
+
}
|
|
161
|
+
exports.format = _format2["default"];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// src/async/Deferred.ts
|
|
2
166
|
var DeferredCanceledError = class extends Error {
|
|
3
167
|
constructor() {
|
|
4
168
|
super("Execution canceled");
|
|
@@ -83,7 +247,7 @@ var Deferred = class {
|
|
|
83
247
|
};
|
|
84
248
|
var Deferred_default = Deferred;
|
|
85
249
|
|
|
86
|
-
//
|
|
250
|
+
// src/async/RateThrottler.ts
|
|
87
251
|
var RateThrottler = class {
|
|
88
252
|
constructor(_frequency) {
|
|
89
253
|
this._frequency = _frequency;
|
|
@@ -103,8 +267,7 @@ var RateThrottler = class {
|
|
|
103
267
|
return slot.promise().then(() => fn());
|
|
104
268
|
} finally {
|
|
105
269
|
this._availableSlots.push(TimeInstant.now().addDuration(this.cooldown));
|
|
106
|
-
if (this._waitingRequests.length > 0)
|
|
107
|
-
this._waitingRequests.shift().resolve();
|
|
270
|
+
if (this._waitingRequests.length > 0) this._waitingRequests.shift().resolve();
|
|
108
271
|
}
|
|
109
272
|
};
|
|
110
273
|
if (this._availableSlots.length > 0) {
|
|
@@ -123,7 +286,7 @@ function throttle(fn, frequence) {
|
|
|
123
286
|
};
|
|
124
287
|
}
|
|
125
288
|
|
|
126
|
-
//
|
|
289
|
+
// src/async/Semaphore.ts
|
|
127
290
|
var Semaphore = class {
|
|
128
291
|
constructor(_availableSlots = 1) {
|
|
129
292
|
this._availableSlots = _availableSlots;
|
|
@@ -167,7 +330,7 @@ var Semaphore = class {
|
|
|
167
330
|
}
|
|
168
331
|
};
|
|
169
332
|
|
|
170
|
-
//
|
|
333
|
+
// src/utils/nulls.ts
|
|
171
334
|
function ensureDefined(v, name = "value") {
|
|
172
335
|
if (isDefined(v))
|
|
173
336
|
return v;
|
|
@@ -193,7 +356,7 @@ function ifNullOrUndefined(source, callback) {
|
|
|
193
356
|
callback();
|
|
194
357
|
}
|
|
195
358
|
|
|
196
|
-
//
|
|
359
|
+
// src/utils/arrays/groupBy.ts
|
|
197
360
|
function groupByString(arr, field) {
|
|
198
361
|
return groupByStringWith(arr, (t) => t[field]);
|
|
199
362
|
}
|
|
@@ -230,7 +393,7 @@ function doGroupByWith(arr, getter) {
|
|
|
230
393
|
}, {});
|
|
231
394
|
}
|
|
232
395
|
|
|
233
|
-
//
|
|
396
|
+
// src/utils/arrays/indexBy.ts
|
|
234
397
|
function indexByString(arr, field) {
|
|
235
398
|
return indexByStringWith(arr, (t) => t[field]);
|
|
236
399
|
}
|
|
@@ -258,7 +421,7 @@ function doIndexByWith(arr, getter) {
|
|
|
258
421
|
}, {});
|
|
259
422
|
}
|
|
260
423
|
|
|
261
|
-
//
|
|
424
|
+
// src/utils/arrays/statistics.ts
|
|
262
425
|
function average(arr) {
|
|
263
426
|
const f = 1 / arr.length;
|
|
264
427
|
return arr.reduce((tot, cur) => tot + cur * f, 0);
|
|
@@ -270,23 +433,21 @@ function sumBy(arr, getter) {
|
|
|
270
433
|
return sum(arr.map(getter));
|
|
271
434
|
}
|
|
272
435
|
function min(arr) {
|
|
273
|
-
if (arr.length === 0)
|
|
274
|
-
throw new Error("Cannot calculate value on empty array");
|
|
436
|
+
if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
|
|
275
437
|
return arr.reduce((min2, cur) => cur < min2 ? cur : min2);
|
|
276
438
|
}
|
|
277
439
|
function minBy(arr, getter) {
|
|
278
440
|
return min(arr.map(getter));
|
|
279
441
|
}
|
|
280
442
|
function max(arr) {
|
|
281
|
-
if (arr.length === 0)
|
|
282
|
-
throw new Error("Cannot calculate value on empty array");
|
|
443
|
+
if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
|
|
283
444
|
return arr.reduce((max2, cur) => cur > max2 ? cur : max2);
|
|
284
445
|
}
|
|
285
446
|
function maxBy(arr, getter) {
|
|
286
447
|
return max(arr.map(getter));
|
|
287
448
|
}
|
|
288
449
|
|
|
289
|
-
//
|
|
450
|
+
// src/utils/functions/constant.ts
|
|
290
451
|
function constant(v) {
|
|
291
452
|
return () => v;
|
|
292
453
|
}
|
|
@@ -301,7 +462,7 @@ var alwaysFalse = constantFalse;
|
|
|
301
462
|
var constantZero = constant(0);
|
|
302
463
|
var constantOne = constant(1);
|
|
303
464
|
|
|
304
|
-
//
|
|
465
|
+
// src/utils/functions/iff.ts
|
|
305
466
|
function iff(firstPredicate, valueIfTrue) {
|
|
306
467
|
if (firstPredicate === true || firstPredicate instanceof Function && firstPredicate() === true) {
|
|
307
468
|
const ret = {
|
|
@@ -318,7 +479,7 @@ function iff(firstPredicate, valueIfTrue) {
|
|
|
318
479
|
}
|
|
319
480
|
}
|
|
320
481
|
|
|
321
|
-
//
|
|
482
|
+
// src/utils/functions.ts
|
|
322
483
|
function isFunction(t) {
|
|
323
484
|
return typeof t === "function";
|
|
324
485
|
}
|
|
@@ -331,24 +492,20 @@ function not(predicate) {
|
|
|
331
492
|
return (t) => !predicate(t);
|
|
332
493
|
}
|
|
333
494
|
function and(...predicates) {
|
|
334
|
-
if (predicates.length === 0)
|
|
335
|
-
|
|
336
|
-
else if (predicates.length === 1)
|
|
337
|
-
return predicates[0];
|
|
495
|
+
if (predicates.length === 0) return constantTrue;
|
|
496
|
+
else if (predicates.length === 1) return predicates[0];
|
|
338
497
|
return (t) => predicates.reduce((prev, cur) => prev ? cur(t) : false, true);
|
|
339
498
|
}
|
|
340
499
|
function or(...predicates) {
|
|
341
|
-
if (predicates.length === 0)
|
|
342
|
-
|
|
343
|
-
else if (predicates.length === 1)
|
|
344
|
-
return predicates[0];
|
|
500
|
+
if (predicates.length === 0) return constantTrue;
|
|
501
|
+
else if (predicates.length === 1) return predicates[0];
|
|
345
502
|
return (t) => predicates.reduce((prev, cur) => prev ? true : cur(t), false);
|
|
346
503
|
}
|
|
347
504
|
function xor(a, b) {
|
|
348
505
|
return (t) => a(t) !== b(t);
|
|
349
506
|
}
|
|
350
507
|
|
|
351
|
-
//
|
|
508
|
+
// src/utils/arrays/uniqBy.ts
|
|
352
509
|
function uniq(arr) {
|
|
353
510
|
return uniqBy(arr, identity);
|
|
354
511
|
}
|
|
@@ -369,15 +526,13 @@ function uniqByKey(arr, key) {
|
|
|
369
526
|
return uniqBy(arr, (item) => item[key]);
|
|
370
527
|
}
|
|
371
528
|
|
|
372
|
-
//
|
|
529
|
+
// src/utils/arrays.ts
|
|
373
530
|
function ensureArray(t) {
|
|
374
|
-
if (isNullOrUndefined(t))
|
|
375
|
-
return [];
|
|
531
|
+
if (isNullOrUndefined(t)) return [];
|
|
376
532
|
return t instanceof Array ? t : [t];
|
|
377
533
|
}
|
|
378
534
|
function ensureReadableArray(t) {
|
|
379
|
-
if (isNullOrUndefined(t))
|
|
380
|
-
return [];
|
|
535
|
+
if (isNullOrUndefined(t)) return [];
|
|
381
536
|
return t instanceof Array ? t : [t];
|
|
382
537
|
}
|
|
383
538
|
function isArray(t) {
|
|
@@ -396,8 +551,7 @@ function upsert(arr, item, isEqual) {
|
|
|
396
551
|
}
|
|
397
552
|
}
|
|
398
553
|
function range(start, end) {
|
|
399
|
-
if (end < start)
|
|
400
|
-
throw new Error();
|
|
554
|
+
if (end < start) throw new Error();
|
|
401
555
|
let length = end - start + 1;
|
|
402
556
|
return new Array(length).fill(1).map((_, i) => start + i);
|
|
403
557
|
}
|
|
@@ -456,8 +610,7 @@ function partition(arr, predicate) {
|
|
|
456
610
|
function mapFirstTruthy(arr, mapFn) {
|
|
457
611
|
for (let i = 0; i < arr.length; i++) {
|
|
458
612
|
const result = mapFn(arr[i]);
|
|
459
|
-
if (result)
|
|
460
|
-
return result;
|
|
613
|
+
if (result) return result;
|
|
461
614
|
}
|
|
462
615
|
return null;
|
|
463
616
|
}
|
|
@@ -465,7 +618,7 @@ function makeArrayEmpty(arr) {
|
|
|
465
618
|
arr.splice(0, arr.length);
|
|
466
619
|
}
|
|
467
620
|
|
|
468
|
-
//
|
|
621
|
+
// src/utils/booleans.ts
|
|
469
622
|
function isTrue(x) {
|
|
470
623
|
return x === true;
|
|
471
624
|
}
|
|
@@ -473,7 +626,7 @@ function isFalse(x) {
|
|
|
473
626
|
return x === false;
|
|
474
627
|
}
|
|
475
628
|
|
|
476
|
-
//
|
|
629
|
+
// src/utils/errors/withTryCatch.ts
|
|
477
630
|
function withTryCatch(fn, errMapFn) {
|
|
478
631
|
try {
|
|
479
632
|
return [fn(), void 0];
|
|
@@ -485,7 +638,7 @@ async function withTryCatchAsync(fn, errMapFn) {
|
|
|
485
638
|
return fn().then((value) => [value, void 0], (e) => [void 0, (errMapFn ?? identity)(asError(e))]);
|
|
486
639
|
}
|
|
487
640
|
|
|
488
|
-
//
|
|
641
|
+
// src/utils/errors.ts
|
|
489
642
|
function asError(e) {
|
|
490
643
|
if (e === void 0 || e === null)
|
|
491
644
|
return new Error("Void message");
|
|
@@ -501,13 +654,12 @@ function isError(e) {
|
|
|
501
654
|
return e instanceof Error;
|
|
502
655
|
}
|
|
503
656
|
|
|
504
|
-
//
|
|
657
|
+
// src/utils/json.ts
|
|
505
658
|
function tryToParseJson(jsonContent) {
|
|
506
659
|
return withTryCatch(() => JSON.parse(jsonContent));
|
|
507
660
|
}
|
|
508
661
|
function jsonCloneDeep(a) {
|
|
509
|
-
if (null === a || "object" !== typeof a)
|
|
510
|
-
return a;
|
|
662
|
+
if (null === a || "object" !== typeof a) return a;
|
|
511
663
|
if (a instanceof Date) {
|
|
512
664
|
return new Date(a.getTime());
|
|
513
665
|
} else if (a instanceof Array) {
|
|
@@ -534,7 +686,7 @@ function omitFromJsonObject(o, ...keys) {
|
|
|
534
686
|
}
|
|
535
687
|
var omit = omitFromJsonObject;
|
|
536
688
|
|
|
537
|
-
//
|
|
689
|
+
// src/utils/numbers/round.ts
|
|
538
690
|
var roundModes = {
|
|
539
691
|
"toNearest": Math.round,
|
|
540
692
|
"toLower": Math.floor,
|
|
@@ -553,7 +705,7 @@ var roundToUpper = (n, precision = 0) => round(n, precision, "toUpper");
|
|
|
553
705
|
var roundTowardsZero = (n, precision = 0) => round(n, precision, "towardsZero");
|
|
554
706
|
var roundAwayFromZero = (n, precision = 0) => round(n, precision, "awayFromZero");
|
|
555
707
|
|
|
556
|
-
//
|
|
708
|
+
// src/utils/numbers.ts
|
|
557
709
|
function ensurePositiveNumber(v, name = "value") {
|
|
558
710
|
if (v !== void 0 && v !== null && v > 0)
|
|
559
711
|
return v;
|
|
@@ -612,18 +764,15 @@ function clamp(n, min2, max2) {
|
|
|
612
764
|
function tryToParseNumber(numberStr) {
|
|
613
765
|
return withTryCatch(() => {
|
|
614
766
|
const type = typeof ensureDefined(numberStr);
|
|
615
|
-
if (type !== "string")
|
|
616
|
-
|
|
617
|
-
if (numberStr.trim().length === 0)
|
|
618
|
-
throw new Error("Invalid number given: " + numberStr);
|
|
767
|
+
if (type !== "string") throw new Error("Invalid number given: " + numberStr);
|
|
768
|
+
if (numberStr.trim().length === 0) throw new Error("Invalid number given: " + numberStr);
|
|
619
769
|
const num = Number(numberStr);
|
|
620
|
-
if (isNaN(num))
|
|
621
|
-
throw new Error("Invalid number given: " + numberStr);
|
|
770
|
+
if (isNaN(num)) throw new Error("Invalid number given: " + numberStr);
|
|
622
771
|
return num;
|
|
623
772
|
});
|
|
624
773
|
}
|
|
625
774
|
|
|
626
|
-
//
|
|
775
|
+
// src/utils/promises.ts
|
|
627
776
|
function asPromise(promisable) {
|
|
628
777
|
return Promise.resolve(promisable);
|
|
629
778
|
}
|
|
@@ -641,7 +790,7 @@ function delayPromise(duration) {
|
|
|
641
790
|
return (result) => duration.promise().then(() => result);
|
|
642
791
|
}
|
|
643
792
|
|
|
644
|
-
//
|
|
793
|
+
// src/utils/random.ts
|
|
645
794
|
var randomInterval = (min2, max2) => randomNumberInInterval(min2, max2);
|
|
646
795
|
var randomPercentage = (min2, max2) => randomNumberInInterval(min2, max2) / 100;
|
|
647
796
|
function randomNumberInInterval(min2, max2) {
|
|
@@ -651,7 +800,7 @@ var randomId = (length) => {
|
|
|
651
800
|
return Math.random().toString(36).substring(2, length + 2);
|
|
652
801
|
};
|
|
653
802
|
|
|
654
|
-
//
|
|
803
|
+
// src/utils/records/entries.ts
|
|
655
804
|
function dictToEntries(obj) {
|
|
656
805
|
return Object.entries(obj);
|
|
657
806
|
}
|
|
@@ -662,7 +811,7 @@ function mapEntries(dict, mapper) {
|
|
|
662
811
|
return entriesToDict(dictToEntries(dict).map((entry) => mapper(entry)));
|
|
663
812
|
}
|
|
664
813
|
|
|
665
|
-
//
|
|
814
|
+
// src/utils/records.ts
|
|
666
815
|
function dictToList(obj) {
|
|
667
816
|
return Object.keys(obj).map((key) => obj[key]);
|
|
668
817
|
}
|
|
@@ -673,7 +822,7 @@ function pick(o, keys) {
|
|
|
673
822
|
}, {});
|
|
674
823
|
}
|
|
675
824
|
|
|
676
|
-
//
|
|
825
|
+
// src/utils/strings/StringParts.ts
|
|
677
826
|
var StringParts = class _StringParts {
|
|
678
827
|
_parts;
|
|
679
828
|
constructor(...parts) {
|
|
@@ -686,8 +835,7 @@ var StringParts = class _StringParts {
|
|
|
686
835
|
return new _StringParts(...this.parts.map((part) => part.toLowerCase()));
|
|
687
836
|
}
|
|
688
837
|
capitalizeFirst() {
|
|
689
|
-
if (!this.length)
|
|
690
|
-
return this;
|
|
838
|
+
if (!this.length) return this;
|
|
691
839
|
return new _StringParts(capitalizeWord(this.first), ...this.tail.map((part) => part.toLowerCase()));
|
|
692
840
|
}
|
|
693
841
|
capitalizeEach() {
|
|
@@ -716,8 +864,7 @@ var StringParts = class _StringParts {
|
|
|
716
864
|
return this.toLowerCase().join("_");
|
|
717
865
|
}
|
|
718
866
|
toCamelCase() {
|
|
719
|
-
if (!this.length)
|
|
720
|
-
return "";
|
|
867
|
+
if (!this.length) return "";
|
|
721
868
|
return [this.first.toLowerCase(), ...this.tail.map(capitalizeWord)].join("");
|
|
722
869
|
}
|
|
723
870
|
toKebabCase() {
|
|
@@ -760,7 +907,7 @@ var StringParts = class _StringParts {
|
|
|
760
907
|
};
|
|
761
908
|
};
|
|
762
909
|
|
|
763
|
-
//
|
|
910
|
+
// src/utils/strings.ts
|
|
764
911
|
function hashCode(str) {
|
|
765
912
|
let hash = 0;
|
|
766
913
|
for (let i = 0; i < str.length; ++i)
|
|
@@ -783,8 +930,7 @@ function stringToNumber(s) {
|
|
|
783
930
|
}
|
|
784
931
|
function pad(str, n, char, where = "left") {
|
|
785
932
|
const length = ensureDefined(str).length;
|
|
786
|
-
if (length >= ensureDefined(n))
|
|
787
|
-
return str;
|
|
933
|
+
if (length >= ensureDefined(n)) return str;
|
|
788
934
|
if (ensureDefined(char).length !== 1)
|
|
789
935
|
throw new Error("Illegal pad character");
|
|
790
936
|
const padding = repeat(char, n - length);
|
|
@@ -824,7 +970,7 @@ function wrapWithString(str, delimiter) {
|
|
|
824
970
|
}
|
|
825
971
|
var wrap = wrapWithString;
|
|
826
972
|
|
|
827
|
-
//
|
|
973
|
+
// src/lazy/Lazy.ts
|
|
828
974
|
var Lazy = class _Lazy {
|
|
829
975
|
_value = void 0;
|
|
830
976
|
_initialized = false;
|
|
@@ -882,7 +1028,7 @@ var Lazy = class _Lazy {
|
|
|
882
1028
|
}
|
|
883
1029
|
};
|
|
884
1030
|
|
|
885
|
-
//
|
|
1031
|
+
// src/lazy/LazyAsync.ts
|
|
886
1032
|
var LazyAsync = class _LazyAsync {
|
|
887
1033
|
_promise = void 0;
|
|
888
1034
|
_pending = false;
|
|
@@ -964,10 +1110,10 @@ var LazyAsync = class _LazyAsync {
|
|
|
964
1110
|
}
|
|
965
1111
|
};
|
|
966
1112
|
|
|
967
|
-
//
|
|
968
|
-
|
|
1113
|
+
// src/time/TimeInstant.ts
|
|
1114
|
+
var import_small_date = __toESM(require_lib());
|
|
969
1115
|
|
|
970
|
-
//
|
|
1116
|
+
// src/time/TimeUnit.ts
|
|
971
1117
|
var TimeUnit = class _TimeUnit {
|
|
972
1118
|
constructor(multiplier) {
|
|
973
1119
|
this.multiplier = multiplier;
|
|
@@ -1001,7 +1147,7 @@ var TimeUnit = class _TimeUnit {
|
|
|
1001
1147
|
static WEEKS = new _TimeUnit(7 * _TimeUnit.DAYS.multiplier);
|
|
1002
1148
|
};
|
|
1003
1149
|
|
|
1004
|
-
//
|
|
1150
|
+
// src/time/TimeBase.ts
|
|
1005
1151
|
var TimeBase = class {
|
|
1006
1152
|
_ms;
|
|
1007
1153
|
constructor(value, unit) {
|
|
@@ -1085,7 +1231,7 @@ var TimeBase = class {
|
|
|
1085
1231
|
}
|
|
1086
1232
|
};
|
|
1087
1233
|
|
|
1088
|
-
//
|
|
1234
|
+
// src/time/TimeDuration.ts
|
|
1089
1235
|
var TimeDuration = class _TimeDuration extends TimeBase {
|
|
1090
1236
|
constructor(value, unit) {
|
|
1091
1237
|
super(value, unit);
|
|
@@ -1127,8 +1273,7 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1127
1273
|
get formatted() {
|
|
1128
1274
|
const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
|
|
1129
1275
|
const units = this.toUnits();
|
|
1130
|
-
if (units.days >= 1)
|
|
1131
|
-
return format2(units.days, "d", units.hours, "h");
|
|
1276
|
+
if (units.days >= 1) return format2(units.days, "d", units.hours, "h");
|
|
1132
1277
|
else if (units.hours >= 1)
|
|
1133
1278
|
return format2(units.hours, "h", units.minutes, "m");
|
|
1134
1279
|
else if (units.minutes >= 1)
|
|
@@ -1327,7 +1472,7 @@ function isAllowedTimeDuration(t) {
|
|
|
1327
1472
|
}
|
|
1328
1473
|
var TimeDuration_default = TimeDuration;
|
|
1329
1474
|
|
|
1330
|
-
//
|
|
1475
|
+
// src/time/TimeInstantBuilder.ts
|
|
1331
1476
|
var isRelativeNumber = (x) => x !== void 0 && x.length > 0 && (x[0] === "+" || x[0] === "-");
|
|
1332
1477
|
var defaultTimeInstantCreationParameters = {
|
|
1333
1478
|
year: { relative: 0, relativeTo: "now" },
|
|
@@ -1396,8 +1541,7 @@ var getFromDate = {
|
|
|
1396
1541
|
};
|
|
1397
1542
|
var toReferenceDate = (x) => {
|
|
1398
1543
|
ensureDefined(x);
|
|
1399
|
-
if (isTimeInstant(x))
|
|
1400
|
-
return x.toDate();
|
|
1544
|
+
if (isTimeInstant(x)) return x.toDate();
|
|
1401
1545
|
return x;
|
|
1402
1546
|
};
|
|
1403
1547
|
function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInstant.now()) {
|
|
@@ -1461,7 +1605,7 @@ function timeInstantBuilder() {
|
|
|
1461
1605
|
return ret;
|
|
1462
1606
|
}
|
|
1463
1607
|
|
|
1464
|
-
//
|
|
1608
|
+
// src/time/TimeInstant.ts
|
|
1465
1609
|
var TimeInstant = class _TimeInstant extends TimeBase {
|
|
1466
1610
|
constructor(number, unit) {
|
|
1467
1611
|
super(number, unit);
|
|
@@ -1580,7 +1724,7 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1580
1724
|
* @returns a string, formatted using the given pattern, at the given timeZone with the given locale.
|
|
1581
1725
|
*/
|
|
1582
1726
|
format(pattern, config = {}) {
|
|
1583
|
-
return format(this.toDate(), pattern, config);
|
|
1727
|
+
return (0, import_small_date.format)(this.toDate(), pattern, config);
|
|
1584
1728
|
}
|
|
1585
1729
|
/**
|
|
1586
1730
|
* @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024Z). The format is meant to always be realiable.
|
|
@@ -1773,7 +1917,7 @@ function isTimeInstant(x) {
|
|
|
1773
1917
|
}
|
|
1774
1918
|
var TimeInstant_default = TimeInstant;
|
|
1775
1919
|
|
|
1776
|
-
//
|
|
1920
|
+
// src/Logger.ts
|
|
1777
1921
|
var LEVELS = ["log", "debug", "info", "warn", "error"];
|
|
1778
1922
|
var timestamp = () => TimeInstant_default.now().asTimeString();
|
|
1779
1923
|
var Logger = class {
|
|
@@ -1810,7 +1954,7 @@ var Logger = class {
|
|
|
1810
1954
|
}
|
|
1811
1955
|
};
|
|
1812
1956
|
|
|
1813
|
-
//
|
|
1957
|
+
// src/Optional.ts
|
|
1814
1958
|
var Optional = class _Optional {
|
|
1815
1959
|
_present;
|
|
1816
1960
|
_value;
|
|
@@ -1924,7 +2068,7 @@ var ErrorCannotInstantiatePresentOptionalWithEmptyValue = class extends Error {
|
|
|
1924
2068
|
}
|
|
1925
2069
|
};
|
|
1926
2070
|
|
|
1927
|
-
//
|
|
2071
|
+
// src/sorting/ComparisonChain.ts
|
|
1928
2072
|
var defaultCompareValueOptions = {
|
|
1929
2073
|
nullsFirst: false,
|
|
1930
2074
|
direction: "ASC"
|
|
@@ -1966,10 +2110,8 @@ function compareBooleans(options) {
|
|
|
1966
2110
|
const fn = (a, b) => {
|
|
1967
2111
|
if (a === b)
|
|
1968
2112
|
return 0;
|
|
1969
|
-
if (isNullOrUndefined(a))
|
|
1970
|
-
|
|
1971
|
-
if (isNullOrUndefined(b))
|
|
1972
|
-
return opts.nullsFirst ? 1 : -1;
|
|
2113
|
+
if (isNullOrUndefined(a)) return opts.nullsFirst ? -1 : 1;
|
|
2114
|
+
if (isNullOrUndefined(b)) return opts.nullsFirst ? 1 : -1;
|
|
1973
2115
|
return a === true && opts.truesFirst || a === false && !opts.truesFirst ? -1 : 1;
|
|
1974
2116
|
};
|
|
1975
2117
|
return (a, b) => applyDirection(fn(a, b), opts.direction);
|
|
@@ -2084,7 +2226,7 @@ function getComparisonFunction(arg) {
|
|
|
2084
2226
|
return arg instanceof ComparisonChain ? arg.compare : arg;
|
|
2085
2227
|
}
|
|
2086
2228
|
|
|
2087
|
-
//
|
|
2229
|
+
// src/sorting/Sorter.ts
|
|
2088
2230
|
var defaultCompareValuesOptions = {
|
|
2089
2231
|
nullsFirst: false
|
|
2090
2232
|
};
|
|
@@ -2150,8 +2292,7 @@ var prioritizeSet = (fns, transform, set, reversed = false) => {
|
|
|
2150
2292
|
var prioritizeArray = (fns, transform, arr, reversed = false) => {
|
|
2151
2293
|
return compareNumbers(fns, (t) => {
|
|
2152
2294
|
const r = transform(t);
|
|
2153
|
-
if (!isDefined(r))
|
|
2154
|
-
return Number.MAX_VALUE;
|
|
2295
|
+
if (!isDefined(r)) return Number.MAX_VALUE;
|
|
2155
2296
|
const indexOf = arr.indexOf(r);
|
|
2156
2297
|
return indexOf === -1 ? Number.MAX_VALUE : indexOf;
|
|
2157
2298
|
}, { direction: reversed ? "DESC" : "ASC", nullsFirst: false });
|
|
@@ -2317,7 +2458,7 @@ var Sorter = {
|
|
|
2317
2458
|
};
|
|
2318
2459
|
var Sorting = Sorter;
|
|
2319
2460
|
|
|
2320
|
-
//
|
|
2461
|
+
// src/time/RandomTimeDuration.ts
|
|
2321
2462
|
function randomize(unit) {
|
|
2322
2463
|
return (a, b) => {
|
|
2323
2464
|
return TimeDuration_default.fromMs(randomInterval(unit.toMs(a), unit.toMs(b)));
|
|
@@ -2333,7 +2474,7 @@ var RandomTimeDuration = class {
|
|
|
2333
2474
|
static days = randomize(TimeUnit.DAYS);
|
|
2334
2475
|
};
|
|
2335
2476
|
|
|
2336
|
-
//
|
|
2477
|
+
// src/time/TimeFrequency.ts
|
|
2337
2478
|
var TimeFrequency = class _TimeFrequency {
|
|
2338
2479
|
constructor(times, period) {
|
|
2339
2480
|
this.times = times;
|
|
@@ -2354,7 +2495,7 @@ var TimeFrequency = class _TimeFrequency {
|
|
|
2354
2495
|
}
|
|
2355
2496
|
};
|
|
2356
2497
|
|
|
2357
|
-
//
|
|
2498
|
+
// src/time/TimeRange.ts
|
|
2358
2499
|
var TimeRange = class _TimeRange {
|
|
2359
2500
|
constructor(start, duration) {
|
|
2360
2501
|
this.start = start;
|
|
@@ -2375,7 +2516,7 @@ var TimeRange = class _TimeRange {
|
|
|
2375
2516
|
}
|
|
2376
2517
|
};
|
|
2377
2518
|
|
|
2378
|
-
//
|
|
2519
|
+
// src/upgrade/errors.ts
|
|
2379
2520
|
var UnavailableUpgradeError = class extends Error {
|
|
2380
2521
|
constructor(data, from, to) {
|
|
2381
2522
|
super(`No transition found to upgrade data from version ${from} to version ${to}.`);
|
|
@@ -2393,7 +2534,7 @@ var EmptyUpgradeError = class extends Error {
|
|
|
2393
2534
|
}
|
|
2394
2535
|
};
|
|
2395
2536
|
|
|
2396
|
-
//
|
|
2537
|
+
// src/upgrade/getTransitionsPath.ts
|
|
2397
2538
|
var DEBUG_ENABLED = false;
|
|
2398
2539
|
function getTransitionsPath(matrix, from, to) {
|
|
2399
2540
|
return internalGetTransitionsPath(matrix, from, to, 0, DEBUG_ENABLED);
|
|
@@ -2442,7 +2583,7 @@ function printTransitions(transitions) {
|
|
|
2442
2583
|
}, "" + transitions[0].from);
|
|
2443
2584
|
}
|
|
2444
2585
|
|
|
2445
|
-
//
|
|
2586
|
+
// src/upgrade/DataUpgrader.ts
|
|
2446
2587
|
var VERSION_FIELD = "$version";
|
|
2447
2588
|
var DataUpgrader = class _DataUpgrader {
|
|
2448
2589
|
constructor(latestVersion) {
|
|
@@ -2656,3 +2797,4 @@ export {
|
|
|
2656
2797
|
wrapWithString,
|
|
2657
2798
|
xor
|
|
2658
2799
|
};
|
|
2800
|
+
//# sourceMappingURL=index.mjs.map
|