@zelgadis87/utils-core 4.5.0 → 4.6.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.
- package/esbuild/index.cjs +149 -249
- package/esbuild/{index.mjs → index.js} +147 -262
- package/esbuild/package.json +39 -0
- package/package.json +14 -102
- package/src/async/Semaphore.ts +8 -6
- package/src/time/TimeDuration.ts +22 -11
- package/src/time/TimeInstant.ts +38 -21
- package/src/utils/arrays/groupBy.ts +11 -11
- package/src/utils/random.ts +9 -3
- package/src/utils/records.ts +12 -0
- package/dist/Logger.d.ts +0 -21
- package/dist/Optional.d.ts +0 -70
- package/dist/async/CancelableDeferred.d.ts +0 -17
- package/dist/async/Deferred.d.ts +0 -34
- package/dist/async/RateThrottler.d.ts +0 -13
- package/dist/async/Semaphore.d.ts +0 -14
- package/dist/async/index.d.ts +0 -4
- package/dist/index.d.ts +0 -8
- package/dist/lazy/Lazy.d.ts +0 -22
- package/dist/lazy/LazyAsync.d.ts +0 -24
- package/dist/lazy/index.d.ts +0 -2
- package/dist/sorting/ComparisonChain.d.ts +0 -57
- package/dist/sorting/Sorter.d.ts +0 -100
- package/dist/sorting/index.d.ts +0 -4
- package/dist/sorting/types.d.ts +0 -5
- package/dist/time/RandomTimeDuration.d.ts +0 -9
- package/dist/time/TimeBase.d.ts +0 -38
- package/dist/time/TimeDuration.d.ts +0 -79
- package/dist/time/TimeFrequency.d.ts +0 -10
- package/dist/time/TimeInstant.d.ts +0 -171
- package/dist/time/TimeInstantBuilder.d.ts +0 -77
- package/dist/time/TimeRange.d.ts +0 -11
- package/dist/time/TimeUnit.d.ts +0 -17
- package/dist/time/index.d.ts +0 -7
- package/dist/time/types.d.ts +0 -26
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/upgrade/DataUpgrader.d.ts +0 -22
- package/dist/upgrade/errors.d.ts +0 -12
- package/dist/upgrade/getTransitionsPath.d.ts +0 -3
- package/dist/upgrade/index.d.ts +0 -2
- package/dist/upgrade/types.d.ts +0 -31
- package/dist/utils/arrays/groupBy.d.ts +0 -9
- package/dist/utils/arrays/indexBy.d.ts +0 -7
- package/dist/utils/arrays/statistics.d.ts +0 -8
- package/dist/utils/arrays/uniqBy.d.ts +0 -4
- package/dist/utils/arrays.d.ts +0 -57
- package/dist/utils/booleans.d.ts +0 -2
- package/dist/utils/empties.d.ts +0 -17
- package/dist/utils/errors/withTryCatch.d.ts +0 -3
- package/dist/utils/errors.d.ts +0 -3
- package/dist/utils/functions/constant.d.ts +0 -10
- package/dist/utils/functions/iff.d.ts +0 -8
- package/dist/utils/functions.d.ts +0 -31
- package/dist/utils/index.d.ts +0 -13
- package/dist/utils/json.d.ts +0 -11
- package/dist/utils/nulls.d.ts +0 -8
- package/dist/utils/numbers/round.d.ts +0 -8
- package/dist/utils/numbers.d.ts +0 -34
- package/dist/utils/primitives.d.ts +0 -3
- package/dist/utils/promises.d.ts +0 -6
- package/dist/utils/random.d.ts +0 -2
- package/dist/utils/records/entries.d.ts +0 -4
- package/dist/utils/records.d.ts +0 -21
- package/dist/utils/strings/StringParts.d.ts +0 -32
- package/dist/utils/strings.d.ts +0 -17
|
@@ -1,168 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
1
|
+
// packages/core/src/async/Deferred.ts
|
|
166
2
|
var DeferredCanceledError = class extends Error {
|
|
167
3
|
constructor() {
|
|
168
4
|
super("Execution canceled");
|
|
@@ -247,7 +83,7 @@ var Deferred = class {
|
|
|
247
83
|
};
|
|
248
84
|
var Deferred_default = Deferred;
|
|
249
85
|
|
|
250
|
-
// src/async/RateThrottler.ts
|
|
86
|
+
// packages/core/src/async/RateThrottler.ts
|
|
251
87
|
var RateThrottler = class {
|
|
252
88
|
constructor(_frequency) {
|
|
253
89
|
this._frequency = _frequency;
|
|
@@ -267,7 +103,8 @@ var RateThrottler = class {
|
|
|
267
103
|
return slot.promise().then(() => fn());
|
|
268
104
|
} finally {
|
|
269
105
|
this._availableSlots.push(TimeInstant.now().addDuration(this.cooldown));
|
|
270
|
-
if (this._waitingRequests.length > 0)
|
|
106
|
+
if (this._waitingRequests.length > 0)
|
|
107
|
+
this._waitingRequests.shift().resolve();
|
|
271
108
|
}
|
|
272
109
|
};
|
|
273
110
|
if (this._availableSlots.length > 0) {
|
|
@@ -286,7 +123,7 @@ function throttle(fn, frequence) {
|
|
|
286
123
|
};
|
|
287
124
|
}
|
|
288
125
|
|
|
289
|
-
// src/async/Semaphore.ts
|
|
126
|
+
// packages/core/src/async/Semaphore.ts
|
|
290
127
|
var Semaphore = class {
|
|
291
128
|
constructor(_availableSlots = 1) {
|
|
292
129
|
this._availableSlots = _availableSlots;
|
|
@@ -315,8 +152,8 @@ var Semaphore = class {
|
|
|
315
152
|
}
|
|
316
153
|
}
|
|
317
154
|
async execute(fn, cooldown = TimeDuration.ZERO) {
|
|
318
|
-
return this._awaitSlot().then(
|
|
319
|
-
void cooldown.
|
|
155
|
+
return this._awaitSlot().then(fn).finally(() => {
|
|
156
|
+
void cooldown.delay(() => this._releaseSlot());
|
|
320
157
|
});
|
|
321
158
|
}
|
|
322
159
|
get availableSlots() {
|
|
@@ -330,7 +167,7 @@ var Semaphore = class {
|
|
|
330
167
|
}
|
|
331
168
|
};
|
|
332
169
|
|
|
333
|
-
// src/utils/nulls.ts
|
|
170
|
+
// packages/core/src/utils/nulls.ts
|
|
334
171
|
function ensureDefined(v, name = "value") {
|
|
335
172
|
if (isDefined(v))
|
|
336
173
|
return v;
|
|
@@ -356,7 +193,7 @@ function ifNullOrUndefined(source, callback) {
|
|
|
356
193
|
callback();
|
|
357
194
|
}
|
|
358
195
|
|
|
359
|
-
// src/utils/arrays/groupBy.ts
|
|
196
|
+
// packages/core/src/utils/arrays/groupBy.ts
|
|
360
197
|
function groupByString(arr, field) {
|
|
361
198
|
return groupByStringWith(arr, (t) => t[field]);
|
|
362
199
|
}
|
|
@@ -382,7 +219,7 @@ function groupBySymbolWith(arr, getter) {
|
|
|
382
219
|
return doGroupByWith(arr, getter);
|
|
383
220
|
}
|
|
384
221
|
function doGroupByWith(arr, getter) {
|
|
385
|
-
return arr.reduce((dict, cur) => {
|
|
222
|
+
return [...arr].reduce((dict, cur) => {
|
|
386
223
|
const key = getter(cur);
|
|
387
224
|
if (key !== null && key !== void 0) {
|
|
388
225
|
const arr2 = dict[key] ?? [];
|
|
@@ -393,7 +230,7 @@ function doGroupByWith(arr, getter) {
|
|
|
393
230
|
}, {});
|
|
394
231
|
}
|
|
395
232
|
|
|
396
|
-
// src/utils/arrays/indexBy.ts
|
|
233
|
+
// packages/core/src/utils/arrays/indexBy.ts
|
|
397
234
|
function indexByString(arr, field) {
|
|
398
235
|
return indexByStringWith(arr, (t) => t[field]);
|
|
399
236
|
}
|
|
@@ -421,7 +258,7 @@ function doIndexByWith(arr, getter) {
|
|
|
421
258
|
}, {});
|
|
422
259
|
}
|
|
423
260
|
|
|
424
|
-
// src/utils/arrays/statistics.ts
|
|
261
|
+
// packages/core/src/utils/arrays/statistics.ts
|
|
425
262
|
function average(arr) {
|
|
426
263
|
const f = 1 / arr.length;
|
|
427
264
|
return arr.reduce((tot, cur) => tot + cur * f, 0);
|
|
@@ -433,21 +270,23 @@ function sumBy(arr, getter) {
|
|
|
433
270
|
return sum(arr.map(getter));
|
|
434
271
|
}
|
|
435
272
|
function min(arr) {
|
|
436
|
-
if (arr.length === 0)
|
|
273
|
+
if (arr.length === 0)
|
|
274
|
+
throw new Error("Cannot calculate value on empty array");
|
|
437
275
|
return arr.reduce((min2, cur) => cur < min2 ? cur : min2);
|
|
438
276
|
}
|
|
439
277
|
function minBy(arr, getter) {
|
|
440
278
|
return min(arr.map(getter));
|
|
441
279
|
}
|
|
442
280
|
function max(arr) {
|
|
443
|
-
if (arr.length === 0)
|
|
281
|
+
if (arr.length === 0)
|
|
282
|
+
throw new Error("Cannot calculate value on empty array");
|
|
444
283
|
return arr.reduce((max2, cur) => cur > max2 ? cur : max2);
|
|
445
284
|
}
|
|
446
285
|
function maxBy(arr, getter) {
|
|
447
286
|
return max(arr.map(getter));
|
|
448
287
|
}
|
|
449
288
|
|
|
450
|
-
// src/utils/functions/constant.ts
|
|
289
|
+
// packages/core/src/utils/functions/constant.ts
|
|
451
290
|
function constant(v) {
|
|
452
291
|
return () => v;
|
|
453
292
|
}
|
|
@@ -462,7 +301,7 @@ var alwaysFalse = constantFalse;
|
|
|
462
301
|
var constantZero = constant(0);
|
|
463
302
|
var constantOne = constant(1);
|
|
464
303
|
|
|
465
|
-
// src/utils/functions/iff.ts
|
|
304
|
+
// packages/core/src/utils/functions/iff.ts
|
|
466
305
|
function iff(firstPredicate, valueIfTrue) {
|
|
467
306
|
if (firstPredicate === true || firstPredicate instanceof Function && firstPredicate() === true) {
|
|
468
307
|
const ret = {
|
|
@@ -479,7 +318,7 @@ function iff(firstPredicate, valueIfTrue) {
|
|
|
479
318
|
}
|
|
480
319
|
}
|
|
481
320
|
|
|
482
|
-
// src/utils/functions.ts
|
|
321
|
+
// packages/core/src/utils/functions.ts
|
|
483
322
|
function isFunction(t) {
|
|
484
323
|
return typeof t === "function";
|
|
485
324
|
}
|
|
@@ -492,20 +331,24 @@ function not(predicate) {
|
|
|
492
331
|
return (t) => !predicate(t);
|
|
493
332
|
}
|
|
494
333
|
function and(...predicates) {
|
|
495
|
-
if (predicates.length === 0)
|
|
496
|
-
|
|
334
|
+
if (predicates.length === 0)
|
|
335
|
+
return constantTrue;
|
|
336
|
+
else if (predicates.length === 1)
|
|
337
|
+
return predicates[0];
|
|
497
338
|
return (t) => predicates.reduce((prev, cur) => prev ? cur(t) : false, true);
|
|
498
339
|
}
|
|
499
340
|
function or(...predicates) {
|
|
500
|
-
if (predicates.length === 0)
|
|
501
|
-
|
|
341
|
+
if (predicates.length === 0)
|
|
342
|
+
return constantTrue;
|
|
343
|
+
else if (predicates.length === 1)
|
|
344
|
+
return predicates[0];
|
|
502
345
|
return (t) => predicates.reduce((prev, cur) => prev ? true : cur(t), false);
|
|
503
346
|
}
|
|
504
347
|
function xor(a, b) {
|
|
505
348
|
return (t) => a(t) !== b(t);
|
|
506
349
|
}
|
|
507
350
|
|
|
508
|
-
// src/utils/arrays/uniqBy.ts
|
|
351
|
+
// packages/core/src/utils/arrays/uniqBy.ts
|
|
509
352
|
function uniq(arr) {
|
|
510
353
|
return uniqBy(arr, identity);
|
|
511
354
|
}
|
|
@@ -526,13 +369,15 @@ function uniqByKey(arr, key) {
|
|
|
526
369
|
return uniqBy(arr, (item) => item[key]);
|
|
527
370
|
}
|
|
528
371
|
|
|
529
|
-
// src/utils/arrays.ts
|
|
372
|
+
// packages/core/src/utils/arrays.ts
|
|
530
373
|
function ensureArray(t) {
|
|
531
|
-
if (isNullOrUndefined(t))
|
|
374
|
+
if (isNullOrUndefined(t))
|
|
375
|
+
return [];
|
|
532
376
|
return t instanceof Array ? t : [t];
|
|
533
377
|
}
|
|
534
378
|
function ensureReadableArray(t) {
|
|
535
|
-
if (isNullOrUndefined(t))
|
|
379
|
+
if (isNullOrUndefined(t))
|
|
380
|
+
return [];
|
|
536
381
|
return t instanceof Array ? t : [t];
|
|
537
382
|
}
|
|
538
383
|
function isArray(t) {
|
|
@@ -551,7 +396,8 @@ function upsert(arr, item, isEqual) {
|
|
|
551
396
|
}
|
|
552
397
|
}
|
|
553
398
|
function range(start, end) {
|
|
554
|
-
if (end < start)
|
|
399
|
+
if (end < start)
|
|
400
|
+
throw new Error();
|
|
555
401
|
let length = end - start + 1;
|
|
556
402
|
return new Array(length).fill(1).map((_, i) => start + i);
|
|
557
403
|
}
|
|
@@ -610,7 +456,8 @@ function partition(arr, predicate) {
|
|
|
610
456
|
function mapFirstTruthy(arr, mapFn) {
|
|
611
457
|
for (let i = 0; i < arr.length; i++) {
|
|
612
458
|
const result = mapFn(arr[i]);
|
|
613
|
-
if (result)
|
|
459
|
+
if (result)
|
|
460
|
+
return result;
|
|
614
461
|
}
|
|
615
462
|
return null;
|
|
616
463
|
}
|
|
@@ -618,7 +465,7 @@ function makeArrayEmpty(arr) {
|
|
|
618
465
|
arr.splice(0, arr.length);
|
|
619
466
|
}
|
|
620
467
|
|
|
621
|
-
// src/utils/booleans.ts
|
|
468
|
+
// packages/core/src/utils/booleans.ts
|
|
622
469
|
function isTrue(x) {
|
|
623
470
|
return x === true;
|
|
624
471
|
}
|
|
@@ -626,7 +473,7 @@ function isFalse(x) {
|
|
|
626
473
|
return x === false;
|
|
627
474
|
}
|
|
628
475
|
|
|
629
|
-
// src/utils/errors/withTryCatch.ts
|
|
476
|
+
// packages/core/src/utils/errors/withTryCatch.ts
|
|
630
477
|
function withTryCatch(fn, errMapFn) {
|
|
631
478
|
try {
|
|
632
479
|
return [fn(), void 0];
|
|
@@ -638,7 +485,7 @@ async function withTryCatchAsync(fn, errMapFn) {
|
|
|
638
485
|
return fn().then((value) => [value, void 0], (e) => [void 0, (errMapFn ?? identity)(asError(e))]);
|
|
639
486
|
}
|
|
640
487
|
|
|
641
|
-
// src/utils/errors.ts
|
|
488
|
+
// packages/core/src/utils/errors.ts
|
|
642
489
|
function asError(e) {
|
|
643
490
|
if (e === void 0 || e === null)
|
|
644
491
|
return new Error("Void message");
|
|
@@ -654,12 +501,13 @@ function isError(e) {
|
|
|
654
501
|
return e instanceof Error;
|
|
655
502
|
}
|
|
656
503
|
|
|
657
|
-
// src/utils/json.ts
|
|
504
|
+
// packages/core/src/utils/json.ts
|
|
658
505
|
function tryToParseJson(jsonContent) {
|
|
659
506
|
return withTryCatch(() => JSON.parse(jsonContent));
|
|
660
507
|
}
|
|
661
508
|
function jsonCloneDeep(a) {
|
|
662
|
-
if (null === a || "object" !== typeof a)
|
|
509
|
+
if (null === a || "object" !== typeof a)
|
|
510
|
+
return a;
|
|
663
511
|
if (a instanceof Date) {
|
|
664
512
|
return new Date(a.getTime());
|
|
665
513
|
} else if (a instanceof Array) {
|
|
@@ -686,7 +534,7 @@ function omitFromJsonObject(o, ...keys) {
|
|
|
686
534
|
}
|
|
687
535
|
var omit = omitFromJsonObject;
|
|
688
536
|
|
|
689
|
-
// src/utils/numbers/round.ts
|
|
537
|
+
// packages/core/src/utils/numbers/round.ts
|
|
690
538
|
var roundModes = {
|
|
691
539
|
"toNearest": Math.round,
|
|
692
540
|
"toLower": Math.floor,
|
|
@@ -705,7 +553,7 @@ var roundToUpper = (n, precision = 0) => round(n, precision, "toUpper");
|
|
|
705
553
|
var roundTowardsZero = (n, precision = 0) => round(n, precision, "towardsZero");
|
|
706
554
|
var roundAwayFromZero = (n, precision = 0) => round(n, precision, "awayFromZero");
|
|
707
555
|
|
|
708
|
-
// src/utils/numbers.ts
|
|
556
|
+
// packages/core/src/utils/numbers.ts
|
|
709
557
|
function ensurePositiveNumber(v, name = "value") {
|
|
710
558
|
if (v !== void 0 && v !== null && v > 0)
|
|
711
559
|
return v;
|
|
@@ -764,15 +612,18 @@ function clamp(n, min2, max2) {
|
|
|
764
612
|
function tryToParseNumber(numberStr) {
|
|
765
613
|
return withTryCatch(() => {
|
|
766
614
|
const type = typeof ensureDefined(numberStr);
|
|
767
|
-
if (type !== "string")
|
|
768
|
-
|
|
615
|
+
if (type !== "string")
|
|
616
|
+
throw new Error("Invalid number given: " + numberStr);
|
|
617
|
+
if (numberStr.trim().length === 0)
|
|
618
|
+
throw new Error("Invalid number given: " + numberStr);
|
|
769
619
|
const num = Number(numberStr);
|
|
770
|
-
if (isNaN(num))
|
|
620
|
+
if (isNaN(num))
|
|
621
|
+
throw new Error("Invalid number given: " + numberStr);
|
|
771
622
|
return num;
|
|
772
623
|
});
|
|
773
624
|
}
|
|
774
625
|
|
|
775
|
-
// src/utils/promises.ts
|
|
626
|
+
// packages/core/src/utils/promises.ts
|
|
776
627
|
function asPromise(promisable) {
|
|
777
628
|
return Promise.resolve(promisable);
|
|
778
629
|
}
|
|
@@ -790,15 +641,17 @@ function delayPromise(duration) {
|
|
|
790
641
|
return (result) => duration.promise().then(() => result);
|
|
791
642
|
}
|
|
792
643
|
|
|
793
|
-
// src/utils/random.ts
|
|
794
|
-
|
|
644
|
+
// packages/core/src/utils/random.ts
|
|
645
|
+
var randomInterval = (min2, max2) => randomNumberInInterval(min2, max2);
|
|
646
|
+
var randomPercentage = (min2, max2) => randomNumberInInterval(min2, max2) / 100;
|
|
647
|
+
function randomNumberInInterval(min2, max2) {
|
|
795
648
|
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
796
649
|
}
|
|
797
|
-
|
|
798
|
-
return
|
|
799
|
-
}
|
|
650
|
+
var randomId = (length) => {
|
|
651
|
+
return Math.random().toString(36).substring(2, length + 2);
|
|
652
|
+
};
|
|
800
653
|
|
|
801
|
-
// src/utils/records/entries.ts
|
|
654
|
+
// packages/core/src/utils/records/entries.ts
|
|
802
655
|
function dictToEntries(obj) {
|
|
803
656
|
return Object.entries(obj);
|
|
804
657
|
}
|
|
@@ -809,7 +662,7 @@ function mapEntries(dict, mapper) {
|
|
|
809
662
|
return entriesToDict(dictToEntries(dict).map((entry) => mapper(entry)));
|
|
810
663
|
}
|
|
811
664
|
|
|
812
|
-
// src/utils/records.ts
|
|
665
|
+
// packages/core/src/utils/records.ts
|
|
813
666
|
function dictToList(obj) {
|
|
814
667
|
return Object.keys(obj).map((key) => obj[key]);
|
|
815
668
|
}
|
|
@@ -820,7 +673,7 @@ function pick(o, keys) {
|
|
|
820
673
|
}, {});
|
|
821
674
|
}
|
|
822
675
|
|
|
823
|
-
// src/utils/strings/StringParts.ts
|
|
676
|
+
// packages/core/src/utils/strings/StringParts.ts
|
|
824
677
|
var StringParts = class _StringParts {
|
|
825
678
|
_parts;
|
|
826
679
|
constructor(...parts) {
|
|
@@ -833,7 +686,8 @@ var StringParts = class _StringParts {
|
|
|
833
686
|
return new _StringParts(...this.parts.map((part) => part.toLowerCase()));
|
|
834
687
|
}
|
|
835
688
|
capitalizeFirst() {
|
|
836
|
-
if (!this.length)
|
|
689
|
+
if (!this.length)
|
|
690
|
+
return this;
|
|
837
691
|
return new _StringParts(capitalizeWord(this.first), ...this.tail.map((part) => part.toLowerCase()));
|
|
838
692
|
}
|
|
839
693
|
capitalizeEach() {
|
|
@@ -862,7 +716,8 @@ var StringParts = class _StringParts {
|
|
|
862
716
|
return this.toLowerCase().join("_");
|
|
863
717
|
}
|
|
864
718
|
toCamelCase() {
|
|
865
|
-
if (!this.length)
|
|
719
|
+
if (!this.length)
|
|
720
|
+
return "";
|
|
866
721
|
return [this.first.toLowerCase(), ...this.tail.map(capitalizeWord)].join("");
|
|
867
722
|
}
|
|
868
723
|
toKebabCase() {
|
|
@@ -905,7 +760,7 @@ var StringParts = class _StringParts {
|
|
|
905
760
|
};
|
|
906
761
|
};
|
|
907
762
|
|
|
908
|
-
// src/utils/strings.ts
|
|
763
|
+
// packages/core/src/utils/strings.ts
|
|
909
764
|
function hashCode(str) {
|
|
910
765
|
let hash = 0;
|
|
911
766
|
for (let i = 0; i < str.length; ++i)
|
|
@@ -928,7 +783,8 @@ function stringToNumber(s) {
|
|
|
928
783
|
}
|
|
929
784
|
function pad(str, n, char, where = "left") {
|
|
930
785
|
const length = ensureDefined(str).length;
|
|
931
|
-
if (length >= ensureDefined(n))
|
|
786
|
+
if (length >= ensureDefined(n))
|
|
787
|
+
return str;
|
|
932
788
|
if (ensureDefined(char).length !== 1)
|
|
933
789
|
throw new Error("Illegal pad character");
|
|
934
790
|
const padding = repeat(char, n - length);
|
|
@@ -968,7 +824,7 @@ function wrapWithString(str, delimiter) {
|
|
|
968
824
|
}
|
|
969
825
|
var wrap = wrapWithString;
|
|
970
826
|
|
|
971
|
-
// src/lazy/Lazy.ts
|
|
827
|
+
// packages/core/src/lazy/Lazy.ts
|
|
972
828
|
var Lazy = class _Lazy {
|
|
973
829
|
_value = void 0;
|
|
974
830
|
_initialized = false;
|
|
@@ -1026,7 +882,7 @@ var Lazy = class _Lazy {
|
|
|
1026
882
|
}
|
|
1027
883
|
};
|
|
1028
884
|
|
|
1029
|
-
// src/lazy/LazyAsync.ts
|
|
885
|
+
// packages/core/src/lazy/LazyAsync.ts
|
|
1030
886
|
var LazyAsync = class _LazyAsync {
|
|
1031
887
|
_promise = void 0;
|
|
1032
888
|
_pending = false;
|
|
@@ -1108,10 +964,10 @@ var LazyAsync = class _LazyAsync {
|
|
|
1108
964
|
}
|
|
1109
965
|
};
|
|
1110
966
|
|
|
1111
|
-
// src/time/TimeInstant.ts
|
|
1112
|
-
|
|
967
|
+
// packages/core/src/time/TimeInstant.ts
|
|
968
|
+
import { format } from "small-date";
|
|
1113
969
|
|
|
1114
|
-
// src/time/TimeUnit.ts
|
|
970
|
+
// packages/core/src/time/TimeUnit.ts
|
|
1115
971
|
var TimeUnit = class _TimeUnit {
|
|
1116
972
|
constructor(multiplier) {
|
|
1117
973
|
this.multiplier = multiplier;
|
|
@@ -1145,7 +1001,7 @@ var TimeUnit = class _TimeUnit {
|
|
|
1145
1001
|
static WEEKS = new _TimeUnit(7 * _TimeUnit.DAYS.multiplier);
|
|
1146
1002
|
};
|
|
1147
1003
|
|
|
1148
|
-
// src/time/TimeBase.ts
|
|
1004
|
+
// packages/core/src/time/TimeBase.ts
|
|
1149
1005
|
var TimeBase = class {
|
|
1150
1006
|
_ms;
|
|
1151
1007
|
constructor(value, unit) {
|
|
@@ -1229,7 +1085,7 @@ var TimeBase = class {
|
|
|
1229
1085
|
}
|
|
1230
1086
|
};
|
|
1231
1087
|
|
|
1232
|
-
// src/time/TimeDuration.ts
|
|
1088
|
+
// packages/core/src/time/TimeDuration.ts
|
|
1233
1089
|
var TimeDuration = class _TimeDuration extends TimeBase {
|
|
1234
1090
|
constructor(value, unit) {
|
|
1235
1091
|
super(value, unit);
|
|
@@ -1262,11 +1118,11 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1262
1118
|
return _TimeDuration.ms(this.ms / times);
|
|
1263
1119
|
}
|
|
1264
1120
|
/**
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1121
|
+
* Returns the current duration in a human readable format, prioritizing the most significant unit of time and excluding the rest.
|
|
1122
|
+
* @todo[2023-06] Should allow more customization options
|
|
1123
|
+
* @todo[2023-06] By default should show the secondary unit only when actually needed (eg, 1h 20m & 3h, instead of 1h 20m & 3h 28m)
|
|
1124
|
+
* @todo[2023-06] Should not allow negative durations, as this is a duration and not an instant.
|
|
1125
|
+
* @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
|
|
1270
1126
|
*/
|
|
1271
1127
|
get formatted() {
|
|
1272
1128
|
const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
|
|
@@ -1296,7 +1152,7 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1296
1152
|
timeout(cb) {
|
|
1297
1153
|
return setTimeout(cb, this.ms);
|
|
1298
1154
|
}
|
|
1299
|
-
|
|
1155
|
+
cancelablePromise() {
|
|
1300
1156
|
const deferred = new Deferred_default();
|
|
1301
1157
|
if (this.ms > 0) {
|
|
1302
1158
|
this.timeout(() => deferred.resolve());
|
|
@@ -1305,8 +1161,18 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1305
1161
|
}
|
|
1306
1162
|
return deferred.asCancelablePromise();
|
|
1307
1163
|
}
|
|
1164
|
+
promise() {
|
|
1165
|
+
if (this.isEmpty())
|
|
1166
|
+
return Promise.resolve();
|
|
1167
|
+
const deferred = new Deferred_default();
|
|
1168
|
+
this.timeout(() => deferred.resolve());
|
|
1169
|
+
return deferred.asPromise();
|
|
1170
|
+
}
|
|
1308
1171
|
delay(cb) {
|
|
1309
|
-
|
|
1172
|
+
void this.promise().then(() => cb());
|
|
1173
|
+
}
|
|
1174
|
+
cancelableDelay(cb) {
|
|
1175
|
+
const deferred = this.cancelablePromise();
|
|
1310
1176
|
void deferred.then(() => {
|
|
1311
1177
|
cb();
|
|
1312
1178
|
}, (err) => {
|
|
@@ -1461,7 +1327,7 @@ function isAllowedTimeDuration(t) {
|
|
|
1461
1327
|
}
|
|
1462
1328
|
var TimeDuration_default = TimeDuration;
|
|
1463
1329
|
|
|
1464
|
-
// src/time/TimeInstantBuilder.ts
|
|
1330
|
+
// packages/core/src/time/TimeInstantBuilder.ts
|
|
1465
1331
|
var isRelativeNumber = (x) => x !== void 0 && x.length > 0 && (x[0] === "+" || x[0] === "-");
|
|
1466
1332
|
var defaultTimeInstantCreationParameters = {
|
|
1467
1333
|
year: { relative: 0, relativeTo: "now" },
|
|
@@ -1530,7 +1396,8 @@ var getFromDate = {
|
|
|
1530
1396
|
};
|
|
1531
1397
|
var toReferenceDate = (x) => {
|
|
1532
1398
|
ensureDefined(x);
|
|
1533
|
-
if (isTimeInstant(x))
|
|
1399
|
+
if (isTimeInstant(x))
|
|
1400
|
+
return x.toDate();
|
|
1534
1401
|
return x;
|
|
1535
1402
|
};
|
|
1536
1403
|
function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInstant.now()) {
|
|
@@ -1594,7 +1461,7 @@ function timeInstantBuilder() {
|
|
|
1594
1461
|
return ret;
|
|
1595
1462
|
}
|
|
1596
1463
|
|
|
1597
|
-
// src/time/TimeInstant.ts
|
|
1464
|
+
// packages/core/src/time/TimeInstant.ts
|
|
1598
1465
|
var TimeInstant = class _TimeInstant extends TimeBase {
|
|
1599
1466
|
constructor(number, unit) {
|
|
1600
1467
|
super(number, unit);
|
|
@@ -1614,6 +1481,14 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1614
1481
|
distanceFromNow() {
|
|
1615
1482
|
return TimeDuration_default.fromMs(Math.abs(this.ms - Date.now()));
|
|
1616
1483
|
}
|
|
1484
|
+
timeLeftFrom(instant) {
|
|
1485
|
+
const distance = this.ms - instant.ms;
|
|
1486
|
+
return TimeDuration_default.fromMs(Math.max(distance, 0));
|
|
1487
|
+
}
|
|
1488
|
+
timeLeftFromNow() {
|
|
1489
|
+
const distance = this.ms - Date.now();
|
|
1490
|
+
return TimeDuration_default.fromMs(Math.max(distance, 0));
|
|
1491
|
+
}
|
|
1617
1492
|
distanceFromStartOfDay() {
|
|
1618
1493
|
return this.distanceFrom(this.atStartOfDay());
|
|
1619
1494
|
}
|
|
@@ -1627,14 +1502,16 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1627
1502
|
return this.atTime({ hours: 23, minutes: 59, seconds: 59, milliseconds: 999 });
|
|
1628
1503
|
}
|
|
1629
1504
|
promise() {
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1505
|
+
return this.timeLeftFromNow().promise();
|
|
1506
|
+
}
|
|
1507
|
+
cancelablePromise() {
|
|
1508
|
+
return this.timeLeftFromNow().cancelablePromise();
|
|
1633
1509
|
}
|
|
1634
1510
|
delay(cb) {
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1511
|
+
return this.timeLeftFromNow().delay(cb);
|
|
1512
|
+
}
|
|
1513
|
+
cancelableDelay(cb) {
|
|
1514
|
+
return this.timeLeftFromNow().cancelableDelay(cb);
|
|
1638
1515
|
}
|
|
1639
1516
|
ensureInTheFuture() {
|
|
1640
1517
|
if (!this.isInTheFuture)
|
|
@@ -1703,7 +1580,7 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1703
1580
|
* @returns a string, formatted using the given pattern, at the given timeZone with the given locale.
|
|
1704
1581
|
*/
|
|
1705
1582
|
format(pattern, config = {}) {
|
|
1706
|
-
return
|
|
1583
|
+
return format(this.toDate(), pattern, config);
|
|
1707
1584
|
}
|
|
1708
1585
|
/**
|
|
1709
1586
|
* @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024Z). The format is meant to always be realiable.
|
|
@@ -1749,20 +1626,23 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1749
1626
|
}
|
|
1750
1627
|
}
|
|
1751
1628
|
/**
|
|
1752
|
-
|
|
1753
|
-
|
|
1629
|
+
* @deprecated: Use {@link distanceFromNow} instead
|
|
1630
|
+
*/
|
|
1631
|
+
// TODO[2023-07-04, Deprecated]: Remove this method in a future version
|
|
1754
1632
|
fromNow() {
|
|
1755
1633
|
return TimeDuration_default.ms(this.ms - Date.now());
|
|
1756
1634
|
}
|
|
1757
1635
|
/**
|
|
1758
|
-
|
|
1759
|
-
|
|
1636
|
+
* @deprecated: Use {@link distanceFrom} instead
|
|
1637
|
+
*/
|
|
1638
|
+
// TODO[2023-07-04, Deprecated]: Remove this method in a future version
|
|
1760
1639
|
from(instant) {
|
|
1761
1640
|
return TimeDuration_default.ms(this.ms - instant.ms);
|
|
1762
1641
|
}
|
|
1763
1642
|
/**
|
|
1764
|
-
|
|
1765
|
-
|
|
1643
|
+
* @deprecated: Use {@link distanceFromUnixTimestamp} instead
|
|
1644
|
+
*/
|
|
1645
|
+
// TODO[2023-07-04, Deprecated]: Remove this method in a future version
|
|
1766
1646
|
fromTimestamp(timestamp2) {
|
|
1767
1647
|
return TimeDuration_default.ms(this.ms - timestamp2);
|
|
1768
1648
|
}
|
|
@@ -1803,8 +1683,8 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1803
1683
|
return timeInstantBuilder();
|
|
1804
1684
|
}
|
|
1805
1685
|
/**
|
|
1806
|
-
|
|
1807
|
-
|
|
1686
|
+
* @deprecated[19/07/2023] Use {@link fromParameters} instead.
|
|
1687
|
+
*/
|
|
1808
1688
|
static fromUnits({ date, month, year, hours, minutes, seconds }) {
|
|
1809
1689
|
const dt = Date.UTC(year, month - 1, date, hours ?? 0, minutes ?? 0, seconds ?? 0);
|
|
1810
1690
|
if (isNaN(dt))
|
|
@@ -1862,9 +1742,9 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1862
1742
|
return this.toDate().getFullYear();
|
|
1863
1743
|
}
|
|
1864
1744
|
/**
|
|
1865
|
-
|
|
1745
|
+
* Returns the week number represented by this instant, according to the ISO 8601 standard.
|
|
1866
1746
|
* Please note that the instant and the week number could be of two different years, eg the friday 1st january is actually part of week 52 of the previous year.
|
|
1867
|
-
|
|
1747
|
+
*/
|
|
1868
1748
|
get weekNumber() {
|
|
1869
1749
|
const date = this.toDate();
|
|
1870
1750
|
const oneDay = 1e3 * 60 * 60 * 24;
|
|
@@ -1875,8 +1755,8 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1875
1755
|
return { weekNumber, year: thursdayOfThisWeek.getFullYear() };
|
|
1876
1756
|
}
|
|
1877
1757
|
/**
|
|
1878
|
-
|
|
1879
|
-
|
|
1758
|
+
* This method is used to provide a better DX when inspecting a TimeInstant object in DevTools.
|
|
1759
|
+
*/
|
|
1880
1760
|
get _time() {
|
|
1881
1761
|
return this.asHumanTimestamp();
|
|
1882
1762
|
}
|
|
@@ -1893,7 +1773,7 @@ function isTimeInstant(x) {
|
|
|
1893
1773
|
}
|
|
1894
1774
|
var TimeInstant_default = TimeInstant;
|
|
1895
1775
|
|
|
1896
|
-
// src/Logger.ts
|
|
1776
|
+
// packages/core/src/Logger.ts
|
|
1897
1777
|
var LEVELS = ["log", "debug", "info", "warn", "error"];
|
|
1898
1778
|
var timestamp = () => TimeInstant_default.now().asTimeString();
|
|
1899
1779
|
var Logger = class {
|
|
@@ -1930,7 +1810,7 @@ var Logger = class {
|
|
|
1930
1810
|
}
|
|
1931
1811
|
};
|
|
1932
1812
|
|
|
1933
|
-
// src/Optional.ts
|
|
1813
|
+
// packages/core/src/Optional.ts
|
|
1934
1814
|
var Optional = class _Optional {
|
|
1935
1815
|
_present;
|
|
1936
1816
|
_value;
|
|
@@ -2044,7 +1924,7 @@ var ErrorCannotInstantiatePresentOptionalWithEmptyValue = class extends Error {
|
|
|
2044
1924
|
}
|
|
2045
1925
|
};
|
|
2046
1926
|
|
|
2047
|
-
// src/sorting/ComparisonChain.ts
|
|
1927
|
+
// packages/core/src/sorting/ComparisonChain.ts
|
|
2048
1928
|
var defaultCompareValueOptions = {
|
|
2049
1929
|
nullsFirst: false,
|
|
2050
1930
|
direction: "ASC"
|
|
@@ -2086,8 +1966,10 @@ function compareBooleans(options) {
|
|
|
2086
1966
|
const fn = (a, b) => {
|
|
2087
1967
|
if (a === b)
|
|
2088
1968
|
return 0;
|
|
2089
|
-
if (isNullOrUndefined(a))
|
|
2090
|
-
|
|
1969
|
+
if (isNullOrUndefined(a))
|
|
1970
|
+
return opts.nullsFirst ? -1 : 1;
|
|
1971
|
+
if (isNullOrUndefined(b))
|
|
1972
|
+
return opts.nullsFirst ? 1 : -1;
|
|
2091
1973
|
return a === true && opts.truesFirst || a === false && !opts.truesFirst ? -1 : 1;
|
|
2092
1974
|
};
|
|
2093
1975
|
return (a, b) => applyDirection(fn(a, b), opts.direction);
|
|
@@ -2202,7 +2084,7 @@ function getComparisonFunction(arg) {
|
|
|
2202
2084
|
return arg instanceof ComparisonChain ? arg.compare : arg;
|
|
2203
2085
|
}
|
|
2204
2086
|
|
|
2205
|
-
// src/sorting/Sorter.ts
|
|
2087
|
+
// packages/core/src/sorting/Sorter.ts
|
|
2206
2088
|
var defaultCompareValuesOptions = {
|
|
2207
2089
|
nullsFirst: false
|
|
2208
2090
|
};
|
|
@@ -2268,7 +2150,8 @@ var prioritizeSet = (fns, transform, set, reversed = false) => {
|
|
|
2268
2150
|
var prioritizeArray = (fns, transform, arr, reversed = false) => {
|
|
2269
2151
|
return compareNumbers(fns, (t) => {
|
|
2270
2152
|
const r = transform(t);
|
|
2271
|
-
if (!isDefined(r))
|
|
2153
|
+
if (!isDefined(r))
|
|
2154
|
+
return Number.MAX_VALUE;
|
|
2272
2155
|
const indexOf = arr.indexOf(r);
|
|
2273
2156
|
return indexOf === -1 ? Number.MAX_VALUE : indexOf;
|
|
2274
2157
|
}, { direction: reversed ? "DESC" : "ASC", nullsFirst: false });
|
|
@@ -2434,7 +2317,7 @@ var Sorter = {
|
|
|
2434
2317
|
};
|
|
2435
2318
|
var Sorting = Sorter;
|
|
2436
2319
|
|
|
2437
|
-
// src/time/RandomTimeDuration.ts
|
|
2320
|
+
// packages/core/src/time/RandomTimeDuration.ts
|
|
2438
2321
|
function randomize(unit) {
|
|
2439
2322
|
return (a, b) => {
|
|
2440
2323
|
return TimeDuration_default.fromMs(randomInterval(unit.toMs(a), unit.toMs(b)));
|
|
@@ -2450,7 +2333,7 @@ var RandomTimeDuration = class {
|
|
|
2450
2333
|
static days = randomize(TimeUnit.DAYS);
|
|
2451
2334
|
};
|
|
2452
2335
|
|
|
2453
|
-
// src/time/TimeFrequency.ts
|
|
2336
|
+
// packages/core/src/time/TimeFrequency.ts
|
|
2454
2337
|
var TimeFrequency = class _TimeFrequency {
|
|
2455
2338
|
constructor(times, period) {
|
|
2456
2339
|
this.times = times;
|
|
@@ -2471,7 +2354,7 @@ var TimeFrequency = class _TimeFrequency {
|
|
|
2471
2354
|
}
|
|
2472
2355
|
};
|
|
2473
2356
|
|
|
2474
|
-
// src/time/TimeRange.ts
|
|
2357
|
+
// packages/core/src/time/TimeRange.ts
|
|
2475
2358
|
var TimeRange = class _TimeRange {
|
|
2476
2359
|
constructor(start, duration) {
|
|
2477
2360
|
this.start = start;
|
|
@@ -2492,7 +2375,7 @@ var TimeRange = class _TimeRange {
|
|
|
2492
2375
|
}
|
|
2493
2376
|
};
|
|
2494
2377
|
|
|
2495
|
-
// src/upgrade/errors.ts
|
|
2378
|
+
// packages/core/src/upgrade/errors.ts
|
|
2496
2379
|
var UnavailableUpgradeError = class extends Error {
|
|
2497
2380
|
constructor(data, from, to) {
|
|
2498
2381
|
super(`No transition found to upgrade data from version ${from} to version ${to}.`);
|
|
@@ -2510,7 +2393,7 @@ var EmptyUpgradeError = class extends Error {
|
|
|
2510
2393
|
}
|
|
2511
2394
|
};
|
|
2512
2395
|
|
|
2513
|
-
// src/upgrade/getTransitionsPath.ts
|
|
2396
|
+
// packages/core/src/upgrade/getTransitionsPath.ts
|
|
2514
2397
|
var DEBUG_ENABLED = false;
|
|
2515
2398
|
function getTransitionsPath(matrix, from, to) {
|
|
2516
2399
|
return internalGetTransitionsPath(matrix, from, to, 0, DEBUG_ENABLED);
|
|
@@ -2559,7 +2442,7 @@ function printTransitions(transitions) {
|
|
|
2559
2442
|
}, "" + transitions[0].from);
|
|
2560
2443
|
}
|
|
2561
2444
|
|
|
2562
|
-
// src/upgrade/DataUpgrader.ts
|
|
2445
|
+
// packages/core/src/upgrade/DataUpgrader.ts
|
|
2563
2446
|
var VERSION_FIELD = "$version";
|
|
2564
2447
|
var DataUpgrader = class _DataUpgrader {
|
|
2565
2448
|
constructor(latestVersion) {
|
|
@@ -2741,7 +2624,9 @@ export {
|
|
|
2741
2624
|
pick,
|
|
2742
2625
|
pluralize,
|
|
2743
2626
|
promiseSequence,
|
|
2627
|
+
randomId,
|
|
2744
2628
|
randomInterval,
|
|
2629
|
+
randomNumberInInterval,
|
|
2745
2630
|
randomPercentage,
|
|
2746
2631
|
range,
|
|
2747
2632
|
repeat,
|