@zelgadis87/utils-core 4.3.4 → 4.4.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/dist/Optional.d.ts +1 -1
- package/dist/async/RateThrottler.d.ts +2 -1
- package/dist/index.d.ts +5 -8
- package/dist/lazy/index.d.ts +2 -0
- package/dist/sorting/ComparisonChain.d.ts +1 -1
- package/dist/sorting/Sorter.d.ts +1 -1
- package/dist/sorting/types.d.ts +1 -1
- package/dist/time/TimeDuration.d.ts +1 -1
- package/dist/time/TimeFrequency.d.ts +1 -1
- package/dist/time/TimeRange.d.ts +2 -2
- package/dist/time/types.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/upgrade/DataUpgrader.d.ts +1 -1
- package/dist/upgrade/getTransitionsPath.d.ts +1 -1
- package/dist/upgrade/types.d.ts +1 -1
- package/dist/utils/{groupBy.d.ts → arrays/groupBy.d.ts} +3 -1
- package/dist/utils/{indexBy.d.ts → arrays/indexBy.d.ts} +1 -1
- package/dist/utils/{math.d.ts → arrays/statistics.d.ts} +1 -2
- package/dist/utils/arrays/uniqBy.d.ts +4 -0
- package/dist/{types → utils}/arrays.d.ts +10 -4
- package/dist/utils/errors/withTryCatch.d.ts +3 -0
- package/dist/{types → utils}/errors.d.ts +1 -0
- package/dist/utils/functions/bindThis.d.ts +1 -0
- package/dist/utils/{iff.d.ts → functions/iff.d.ts} +3 -3
- package/dist/{types → utils}/functions.d.ts +4 -0
- package/dist/utils/index.d.ts +13 -19
- package/dist/utils/json.d.ts +11 -0
- package/dist/{types → utils}/numbers.d.ts +3 -1
- package/dist/utils/primitives.d.ts +3 -0
- package/dist/utils/random.d.ts +2 -0
- package/dist/utils/{entries.d.ts → records/entries.d.ts} +1 -1
- package/dist/{types → utils}/records.d.ts +1 -0
- package/dist/{types/strings.d.ts → utils/strings/StringParts.d.ts} +2 -15
- package/dist/utils/strings.d.ts +17 -0
- package/esbuild/index.cjs +548 -697
- package/esbuild/index.mjs +540 -693
- package/package.json +3 -40
- package/src/Logger.ts +1 -1
- package/src/Optional.ts +2 -2
- package/src/async/Deferred.ts +1 -1
- package/src/async/RateThrottler.ts +8 -1
- package/src/async/index.ts +1 -0
- package/src/index.ts +5 -8
- package/src/{Lazy.ts → lazy/Lazy.ts} +1 -1
- package/src/{LazyAsync.ts → lazy/LazyAsync.ts} +1 -1
- package/src/lazy/index.ts +3 -0
- package/src/sorting/ComparisonChain.ts +2 -2
- package/src/sorting/Sorter.ts +2 -2
- package/src/sorting/types.ts +1 -1
- package/src/time/RandomTimeDuration.ts +1 -1
- package/src/time/TimeDuration.ts +1 -2
- package/src/time/TimeFrequency.ts +1 -1
- package/src/time/TimeInstantBuilder.ts +2 -2
- package/src/time/TimeRange.ts +2 -2
- package/src/time/types.ts +1 -1
- package/src/upgrade/DataUpgrader.ts +1 -1
- package/src/upgrade/getTransitionsPath.ts +1 -1
- package/src/upgrade/types.ts +1 -1
- package/src/utils/{groupBy.ts → arrays/groupBy.ts} +1 -1
- package/src/utils/{indexBy.ts → arrays/indexBy.ts} +1 -1
- package/src/utils/{math.ts → arrays/statistics.ts} +1 -13
- package/src/utils/arrays/uniqBy.ts +24 -0
- package/src/{types → utils}/arrays.ts +15 -6
- package/src/utils/errors/withTryCatch.ts +15 -0
- package/src/{types → utils}/errors.ts +2 -0
- package/src/utils/functions/bindThis.ts +4 -0
- package/src/utils/{iff.ts → functions/iff.ts} +4 -2
- package/src/{types → utils}/functions.ts +6 -0
- package/src/utils/index.ts +13 -19
- package/src/utils/json.ts +49 -0
- package/src/utils/{round.ts → numbers/round.ts} +1 -0
- package/src/{types → utils}/numbers.ts +15 -1
- package/src/utils/primitives.ts +5 -0
- package/src/utils/random.ts +9 -0
- package/src/utils/{entries.ts → records/entries.ts} +1 -1
- package/src/{types → utils}/records.ts +2 -0
- package/src/utils/strings/StringParts.ts +114 -0
- package/src/utils/strings.ts +91 -0
- package/dist/random/index.d.ts +0 -2
- package/dist/random/randomInterval.d.ts +0 -1
- package/dist/random/randomPercentage.d.ts +0 -1
- package/dist/types/index.d.ts +0 -14
- package/dist/types/json.d.ts +0 -7
- package/dist/utils/bindThis.d.ts +0 -1
- package/dist/utils/jsonCloneDeep.d.ts +0 -2
- package/dist/utils/noop.d.ts +0 -1
- package/dist/utils/omit.d.ts +0 -2
- package/dist/utils/sortBy.d.ts +0 -7
- package/dist/utils/throttle.d.ts +0 -3
- package/dist/utils/uniq.d.ts +0 -1
- package/dist/utils/uniqBy.d.ts +0 -2
- package/dist/utils/uniqByKey.d.ts +0 -1
- package/dist/utils/upsert.d.ts +0 -0
- package/dist/utils/withTryCatch.d.ts +0 -2
- package/dist/utils/withTryCatchAsync.d.ts +0 -2
- package/dist/utils/wrap.d.ts +0 -1
- package/src/random/index.ts +0 -3
- package/src/random/randomInterval.ts +0 -4
- package/src/random/randomPercentage.ts +0 -6
- package/src/types/index.ts +0 -20
- package/src/types/json.ts +0 -15
- package/src/types/strings.ts +0 -191
- package/src/utils/bindThis.ts +0 -4
- package/src/utils/jsonCloneDeep.ts +0 -31
- package/src/utils/noop.ts +0 -2
- package/src/utils/omit.ts +0 -8
- package/src/utils/sortBy.ts +0 -27
- package/src/utils/throttle.ts +0 -10
- package/src/utils/uniq.ts +0 -6
- package/src/utils/uniqBy.ts +0 -15
- package/src/utils/uniqByKey.ts +0 -5
- package/src/utils/upsert.ts +0 -2
- package/src/utils/withTryCatch.ts +0 -9
- package/src/utils/withTryCatchAsync.ts +0 -5
- package/src/utils/wrap.ts +0 -4
- /package/dist/{Lazy.d.ts → lazy/Lazy.d.ts} +0 -0
- /package/dist/{LazyAsync.d.ts → lazy/LazyAsync.d.ts} +0 -0
- /package/dist/{types → utils}/booleans.d.ts +0 -0
- /package/dist/{types → utils}/empties.d.ts +0 -0
- /package/dist/utils/{constant.d.ts → functions/constant.d.ts} +0 -0
- /package/dist/{types → utils}/nulls.d.ts +0 -0
- /package/dist/utils/{round.d.ts → numbers/round.d.ts} +0 -0
- /package/dist/{types → utils}/promises.d.ts +0 -0
- /package/src/{types → utils}/booleans.ts +0 -0
- /package/src/{types → utils}/empties.ts +0 -0
- /package/src/utils/{constant.ts → functions/constant.ts} +0 -0
- /package/src/{types → utils}/nulls.ts +0 -0
- /package/src/{types → utils}/promises.ts +0 -0
package/esbuild/index.mjs
CHANGED
|
@@ -162,7 +162,329 @@ var require_lib = __commonJS({
|
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
-
// src/
|
|
165
|
+
// src/async/Deferred.ts
|
|
166
|
+
var DeferredCanceledError = class extends Error {
|
|
167
|
+
constructor() {
|
|
168
|
+
super("Execution canceled");
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var Deferred = class {
|
|
172
|
+
_pending;
|
|
173
|
+
_internals;
|
|
174
|
+
get pending() {
|
|
175
|
+
return this._pending;
|
|
176
|
+
}
|
|
177
|
+
/** @deprecated: Use resolve, then and catch directly; use asPromise to return a promise type. */
|
|
178
|
+
get promise() {
|
|
179
|
+
return this._internals.promise;
|
|
180
|
+
}
|
|
181
|
+
constructor() {
|
|
182
|
+
this._pending = true;
|
|
183
|
+
this._internals = this.createInternals();
|
|
184
|
+
}
|
|
185
|
+
resolve(val) {
|
|
186
|
+
if (!this._pending)
|
|
187
|
+
throw new Error("Illegal state exception");
|
|
188
|
+
this.resolveIfPending(val);
|
|
189
|
+
}
|
|
190
|
+
reject(reason) {
|
|
191
|
+
if (!this._pending)
|
|
192
|
+
throw new Error("Illegal state exception");
|
|
193
|
+
this.rejectIfPending(reason);
|
|
194
|
+
}
|
|
195
|
+
cancel() {
|
|
196
|
+
if (!this._pending)
|
|
197
|
+
throw new Error("Illegal state exception");
|
|
198
|
+
this.cancelIfPending();
|
|
199
|
+
}
|
|
200
|
+
resolveIfPending(val) {
|
|
201
|
+
if (!this._pending)
|
|
202
|
+
return;
|
|
203
|
+
this._pending = false;
|
|
204
|
+
this._internals.resolve(val);
|
|
205
|
+
}
|
|
206
|
+
rejectIfPending(reason) {
|
|
207
|
+
if (!this._pending)
|
|
208
|
+
return;
|
|
209
|
+
this._pending = false;
|
|
210
|
+
this._internals.reject(reason);
|
|
211
|
+
}
|
|
212
|
+
cancelIfPending() {
|
|
213
|
+
if (!this._pending)
|
|
214
|
+
return;
|
|
215
|
+
this.reject(new DeferredCanceledError());
|
|
216
|
+
}
|
|
217
|
+
then(onFulfilled, onRejected) {
|
|
218
|
+
return this._internals.promise.then(onFulfilled, onRejected);
|
|
219
|
+
}
|
|
220
|
+
catch(onRejected) {
|
|
221
|
+
return this._internals.promise.catch(onRejected);
|
|
222
|
+
}
|
|
223
|
+
finally(onfinally) {
|
|
224
|
+
return this._internals.promise.finally(onfinally);
|
|
225
|
+
}
|
|
226
|
+
asPromise() {
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
asCancelablePromise() {
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
createInternals() {
|
|
233
|
+
let resolveSelf, rejectSelf;
|
|
234
|
+
const promise = new Promise((resolve, reject) => {
|
|
235
|
+
resolveSelf = resolve;
|
|
236
|
+
rejectSelf = reject;
|
|
237
|
+
});
|
|
238
|
+
return {
|
|
239
|
+
promise,
|
|
240
|
+
resolve: resolveSelf,
|
|
241
|
+
reject: rejectSelf
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
get [Symbol.toStringTag]() {
|
|
245
|
+
return "[object Deferred]";
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
var Deferred_default = Deferred;
|
|
249
|
+
|
|
250
|
+
// src/async/RateThrottler.ts
|
|
251
|
+
var RateThrottler = class {
|
|
252
|
+
constructor(_frequency) {
|
|
253
|
+
this._frequency = _frequency;
|
|
254
|
+
const initialOffset = this.cooldown.divideBy(_frequency.times);
|
|
255
|
+
this._availableSlots = new Array(_frequency.times).fill(0).map((_, i) => TimeInstant.now().addMs(i * initialOffset.ms));
|
|
256
|
+
this._waitingRequests = [];
|
|
257
|
+
}
|
|
258
|
+
_availableSlots;
|
|
259
|
+
_waitingRequests;
|
|
260
|
+
get cooldown() {
|
|
261
|
+
return this._frequency.period;
|
|
262
|
+
}
|
|
263
|
+
async execute(fn) {
|
|
264
|
+
const wrappedFn = async () => {
|
|
265
|
+
const slot = this._availableSlots.shift();
|
|
266
|
+
try {
|
|
267
|
+
return slot.promise().then(() => fn());
|
|
268
|
+
} finally {
|
|
269
|
+
this._availableSlots.push(TimeInstant.now().addDuration(this.cooldown));
|
|
270
|
+
if (this._waitingRequests.length > 0) this._waitingRequests.shift().resolve();
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
if (this._availableSlots.length > 0) {
|
|
274
|
+
return wrappedFn();
|
|
275
|
+
} else {
|
|
276
|
+
const waitingRequest = new Deferred_default();
|
|
277
|
+
this._waitingRequests.push(waitingRequest);
|
|
278
|
+
return waitingRequest.then(() => wrappedFn());
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
function throttle(fn, frequence) {
|
|
283
|
+
const semaphore = new RateThrottler(frequence);
|
|
284
|
+
return (...t) => {
|
|
285
|
+
return semaphore.execute(async () => fn(...t));
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/async/Semaphore.ts
|
|
290
|
+
var Semaphore = class {
|
|
291
|
+
constructor(_availableSlots = 1) {
|
|
292
|
+
this._availableSlots = _availableSlots;
|
|
293
|
+
this._queuedRequests = [];
|
|
294
|
+
}
|
|
295
|
+
_queuedRequests;
|
|
296
|
+
_inProgress = 0;
|
|
297
|
+
async _awaitSlot() {
|
|
298
|
+
if (this._availableSlots > 0) {
|
|
299
|
+
this._availableSlots -= 1;
|
|
300
|
+
this._inProgress += 1;
|
|
301
|
+
return void 0;
|
|
302
|
+
} else {
|
|
303
|
+
const deferred = new Deferred_default();
|
|
304
|
+
this._queuedRequests.push(deferred);
|
|
305
|
+
return deferred.asPromise();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
_releaseSlot() {
|
|
309
|
+
const waitingSlotToResolve = this._queuedRequests.shift();
|
|
310
|
+
if (waitingSlotToResolve) {
|
|
311
|
+
waitingSlotToResolve.resolve();
|
|
312
|
+
} else {
|
|
313
|
+
this._availableSlots += 1;
|
|
314
|
+
this._inProgress -= 1;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
async execute(fn, cooldown = TimeDuration.ZERO) {
|
|
318
|
+
return this._awaitSlot().then(() => fn()).finally(() => {
|
|
319
|
+
void cooldown.promise().then(() => this._releaseSlot());
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
get availableSlots() {
|
|
323
|
+
return this._availableSlots;
|
|
324
|
+
}
|
|
325
|
+
get queueSize() {
|
|
326
|
+
return this._queuedRequests.length;
|
|
327
|
+
}
|
|
328
|
+
get inProgressSize() {
|
|
329
|
+
return this._inProgress;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// src/utils/arrays/groupBy.ts
|
|
334
|
+
function groupByString(arr, field) {
|
|
335
|
+
return groupByStringWith(arr, (t) => t[field]);
|
|
336
|
+
}
|
|
337
|
+
function groupByNumber(arr, field) {
|
|
338
|
+
return groupByNumberWith(arr, (t) => t[field]);
|
|
339
|
+
}
|
|
340
|
+
function groupByBoolean(arr, field) {
|
|
341
|
+
return groupByBooleanWith(arr, (t) => t[field]);
|
|
342
|
+
}
|
|
343
|
+
function groupBySymbol(arr, field) {
|
|
344
|
+
return groupBySymbolWith(arr, (t) => t[field]);
|
|
345
|
+
}
|
|
346
|
+
function groupByStringWith(arr, getter) {
|
|
347
|
+
return doGroupByWith(arr, getter);
|
|
348
|
+
}
|
|
349
|
+
function groupByNumberWith(arr, getter) {
|
|
350
|
+
return doGroupByWith(arr, getter);
|
|
351
|
+
}
|
|
352
|
+
function groupByBooleanWith(arr, getter) {
|
|
353
|
+
return doGroupByWith(arr, (item) => getter(item) ? "true" : "false");
|
|
354
|
+
}
|
|
355
|
+
function groupBySymbolWith(arr, getter) {
|
|
356
|
+
return doGroupByWith(arr, getter);
|
|
357
|
+
}
|
|
358
|
+
function doGroupByWith(arr, getter) {
|
|
359
|
+
return arr.reduce((dict, cur) => {
|
|
360
|
+
const key = getter(cur);
|
|
361
|
+
if (key !== null && key !== void 0) {
|
|
362
|
+
const arr2 = dict[key] ?? [];
|
|
363
|
+
arr2.push(cur);
|
|
364
|
+
dict[key] = arr2;
|
|
365
|
+
}
|
|
366
|
+
return dict;
|
|
367
|
+
}, {});
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// src/utils/arrays/indexBy.ts
|
|
371
|
+
function indexByString(arr, field) {
|
|
372
|
+
return indexByStringWith(arr, (t) => t[field]);
|
|
373
|
+
}
|
|
374
|
+
function indexByNumber(arr, field) {
|
|
375
|
+
return indexByNumberWith(arr, (t) => t[field]);
|
|
376
|
+
}
|
|
377
|
+
function indexBySymbol(arr, field) {
|
|
378
|
+
return indexBySymbolWith(arr, (t) => t[field]);
|
|
379
|
+
}
|
|
380
|
+
function indexByStringWith(arr, getter) {
|
|
381
|
+
return doIndexByWith(arr, getter);
|
|
382
|
+
}
|
|
383
|
+
function indexByNumberWith(arr, getter) {
|
|
384
|
+
return doIndexByWith(arr, getter);
|
|
385
|
+
}
|
|
386
|
+
function indexBySymbolWith(arr, getter) {
|
|
387
|
+
return doIndexByWith(arr, getter);
|
|
388
|
+
}
|
|
389
|
+
function doIndexByWith(arr, getter) {
|
|
390
|
+
return arr.reduce((dict, cur) => {
|
|
391
|
+
const key = getter(cur);
|
|
392
|
+
if (key !== null && key !== void 0)
|
|
393
|
+
dict[key] = cur;
|
|
394
|
+
return dict;
|
|
395
|
+
}, {});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/utils/arrays/statistics.ts
|
|
399
|
+
function average(arr) {
|
|
400
|
+
const f = 1 / arr.length;
|
|
401
|
+
return arr.reduce((tot, cur) => tot + cur * f, 0);
|
|
402
|
+
}
|
|
403
|
+
function sum(arr) {
|
|
404
|
+
return arr.reduce((tot, cur) => tot + cur, 0);
|
|
405
|
+
}
|
|
406
|
+
function sumBy(arr, getter) {
|
|
407
|
+
return sum(arr.map(getter));
|
|
408
|
+
}
|
|
409
|
+
function min(arr) {
|
|
410
|
+
if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
|
|
411
|
+
return arr.reduce((min2, cur) => cur < min2 ? cur : min2);
|
|
412
|
+
}
|
|
413
|
+
function minBy(arr, getter) {
|
|
414
|
+
return min(arr.map(getter));
|
|
415
|
+
}
|
|
416
|
+
function max(arr) {
|
|
417
|
+
if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
|
|
418
|
+
return arr.reduce((max2, cur) => cur > max2 ? cur : max2);
|
|
419
|
+
}
|
|
420
|
+
function maxBy(arr, getter) {
|
|
421
|
+
return max(arr.map(getter));
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/utils/functions/bindThis.ts
|
|
425
|
+
function bindThis(fn, _this) {
|
|
426
|
+
return fn.bind(_this);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// src/utils/functions/constant.ts
|
|
430
|
+
function constant(v) {
|
|
431
|
+
return () => v;
|
|
432
|
+
}
|
|
433
|
+
function identity(t) {
|
|
434
|
+
return t;
|
|
435
|
+
}
|
|
436
|
+
var constantNull = constant(null);
|
|
437
|
+
var constantTrue = constant(true);
|
|
438
|
+
var constantFalse = constant(false);
|
|
439
|
+
var constantZero = constant(0);
|
|
440
|
+
var constantOne = constant(1);
|
|
441
|
+
|
|
442
|
+
// src/utils/functions/iff.ts
|
|
443
|
+
function iff(firstPredicate, valueIfTrue) {
|
|
444
|
+
if (firstPredicate === true || firstPredicate instanceof Function && firstPredicate() === true) {
|
|
445
|
+
const ret = {
|
|
446
|
+
elseIf: () => ret,
|
|
447
|
+
otherwise: () => valueIfTrue
|
|
448
|
+
};
|
|
449
|
+
return ret;
|
|
450
|
+
} else {
|
|
451
|
+
const ret = {
|
|
452
|
+
elseIf: (elseIf, valueIfElseIfTrue) => iff(elseIf, valueIfElseIfTrue),
|
|
453
|
+
otherwise: (valueIfElse) => valueIfElse
|
|
454
|
+
};
|
|
455
|
+
return ret;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// src/utils/functions.ts
|
|
460
|
+
function isFunction(t) {
|
|
461
|
+
return typeof t === "function";
|
|
462
|
+
}
|
|
463
|
+
function noop() {
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/utils/arrays/uniqBy.ts
|
|
467
|
+
function uniq(arr) {
|
|
468
|
+
return uniqBy(arr, identity);
|
|
469
|
+
}
|
|
470
|
+
function uniqBy(arr, getter) {
|
|
471
|
+
return arr.reduce((dict, cur) => {
|
|
472
|
+
const key = getter(cur);
|
|
473
|
+
if (dict.keys.includes(key)) {
|
|
474
|
+
return dict;
|
|
475
|
+
} else {
|
|
476
|
+
return {
|
|
477
|
+
keys: [...dict.keys, key],
|
|
478
|
+
values: [...dict.values, cur]
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
}, { keys: [], values: [] }).values;
|
|
482
|
+
}
|
|
483
|
+
function uniqByKey(arr, key) {
|
|
484
|
+
return uniqBy(arr, (item) => item[key]);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/utils/arrays.ts
|
|
166
488
|
function ensureArray(t) {
|
|
167
489
|
return t instanceof Array ? t : [t];
|
|
168
490
|
}
|
|
@@ -207,11 +529,15 @@ function extendArrayWith(arr, propsFn) {
|
|
|
207
529
|
function reverse(arr) {
|
|
208
530
|
return [...arr].reverse();
|
|
209
531
|
}
|
|
210
|
-
function
|
|
532
|
+
function first(arr, defaultValue = null) {
|
|
211
533
|
return arr.length ? arr[0] : defaultValue;
|
|
212
534
|
}
|
|
213
535
|
function last(arr, defaultValue = null) {
|
|
214
|
-
return
|
|
536
|
+
return arr.length ? arr[arr.length - 1] : defaultValue;
|
|
537
|
+
}
|
|
538
|
+
var head = first;
|
|
539
|
+
function tail(arr) {
|
|
540
|
+
return arr.length ? arr.slice(1) : [];
|
|
215
541
|
}
|
|
216
542
|
function sortedArray(arr, sortFn) {
|
|
217
543
|
return [...arr].sort(sortFn);
|
|
@@ -226,7 +552,7 @@ function flatMapTruthys(arr, mapper) {
|
|
|
226
552
|
return arr.flatMap(mapper).filter((value) => value !== void 0);
|
|
227
553
|
}
|
|
228
554
|
|
|
229
|
-
// src/
|
|
555
|
+
// src/utils/booleans.ts
|
|
230
556
|
function isTrue(x) {
|
|
231
557
|
return x === true;
|
|
232
558
|
}
|
|
@@ -234,7 +560,19 @@ function isFalse(x) {
|
|
|
234
560
|
return x === false;
|
|
235
561
|
}
|
|
236
562
|
|
|
237
|
-
// src/
|
|
563
|
+
// src/utils/errors/withTryCatch.ts
|
|
564
|
+
function withTryCatch(fn) {
|
|
565
|
+
try {
|
|
566
|
+
return [fn(), void 0];
|
|
567
|
+
} catch (e) {
|
|
568
|
+
return [void 0, asError(e)];
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
async function withTryCatchAsync(fn) {
|
|
572
|
+
return fn().then((value) => [value, void 0], (e) => [void 0, asError(e)]);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// src/utils/errors.ts
|
|
238
576
|
function asError(e) {
|
|
239
577
|
if (e === void 0 || e === null)
|
|
240
578
|
return new Error("Void message");
|
|
@@ -250,22 +588,39 @@ function isError(e) {
|
|
|
250
588
|
return e instanceof Error;
|
|
251
589
|
}
|
|
252
590
|
|
|
253
|
-
// src/
|
|
254
|
-
function isFunction(t) {
|
|
255
|
-
return typeof t === "function";
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// src/types/json.ts
|
|
591
|
+
// src/utils/json.ts
|
|
259
592
|
function tryToParseJson(jsonContent) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
593
|
+
return withTryCatch(() => JSON.parse(jsonContent));
|
|
594
|
+
}
|
|
595
|
+
function jsonCloneDeep(a) {
|
|
596
|
+
if (null === a || "object" !== typeof a) return a;
|
|
597
|
+
if (a instanceof Date) {
|
|
598
|
+
return new Date(a.getTime());
|
|
599
|
+
} else if (a instanceof Array) {
|
|
600
|
+
const copy = [];
|
|
601
|
+
for (let i = 0, len = a.length; i < len; i++) {
|
|
602
|
+
copy[i] = jsonCloneDeep(a[i]);
|
|
603
|
+
}
|
|
604
|
+
return copy;
|
|
605
|
+
} else if (a instanceof Object) {
|
|
606
|
+
const copy = {};
|
|
607
|
+
for (let attr in a) {
|
|
608
|
+
if (a.hasOwnProperty(attr))
|
|
609
|
+
copy[attr] = jsonCloneDeep(a[attr]);
|
|
610
|
+
}
|
|
611
|
+
return copy;
|
|
265
612
|
}
|
|
613
|
+
throw new Error("Unable to copy obj! Its type isn't supported.");
|
|
614
|
+
}
|
|
615
|
+
function omitFromJsonObject(o, ...keys) {
|
|
616
|
+
return keys.reduce((obj, key) => {
|
|
617
|
+
delete obj[key];
|
|
618
|
+
return obj;
|
|
619
|
+
}, { ...o });
|
|
266
620
|
}
|
|
621
|
+
var omit = omitFromJsonObject;
|
|
267
622
|
|
|
268
|
-
// src/
|
|
623
|
+
// src/utils/nulls.ts
|
|
269
624
|
function ensureDefined(v, name = "value") {
|
|
270
625
|
if (isDefined(v))
|
|
271
626
|
return v;
|
|
@@ -291,7 +646,26 @@ function ifNullOrUndefined(source, callback) {
|
|
|
291
646
|
callback();
|
|
292
647
|
}
|
|
293
648
|
|
|
294
|
-
// src/
|
|
649
|
+
// src/utils/numbers/round.ts
|
|
650
|
+
var roundModes = {
|
|
651
|
+
"toNearest": Math.round,
|
|
652
|
+
"toLower": Math.floor,
|
|
653
|
+
"toUpper": Math.ceil,
|
|
654
|
+
"towardsZero": (n) => n > 0 ? Math.floor(n) : Math.ceil(n),
|
|
655
|
+
"awayFromZero": (n) => n > 0 ? Math.ceil(n) : Math.floor(n)
|
|
656
|
+
};
|
|
657
|
+
function round(n, precision = 0, mode = "toNearest") {
|
|
658
|
+
const base = 10;
|
|
659
|
+
const power = Math.pow(base, precision);
|
|
660
|
+
return roundModes[mode](n * power) / power;
|
|
661
|
+
}
|
|
662
|
+
var roundToNearest = (n, precision = 0) => round(n, precision, "toNearest");
|
|
663
|
+
var roundToLower = (n, precision = 0) => round(n, precision, "toLower");
|
|
664
|
+
var roundToUpper = (n, precision = 0) => round(n, precision, "toUpper");
|
|
665
|
+
var roundTowardsZero = (n, precision = 0) => round(n, precision, "towardsZero");
|
|
666
|
+
var roundAwayFromZero = (n, precision = 0) => round(n, precision, "awayFromZero");
|
|
667
|
+
|
|
668
|
+
// src/utils/numbers.ts
|
|
295
669
|
function ensurePositiveNumber(v, name = "value") {
|
|
296
670
|
if (v !== void 0 && v !== null && v > 0)
|
|
297
671
|
return v;
|
|
@@ -336,8 +710,19 @@ function isNegativeNumber(v) {
|
|
|
336
710
|
function isZero(v) {
|
|
337
711
|
return v === 0;
|
|
338
712
|
}
|
|
713
|
+
function clamp(n, min2, max2) {
|
|
714
|
+
if (min2 === null || max2 === null || n === null || isNaN(min2) || isNaN(max2) || isNaN(n) || min2 > max2)
|
|
715
|
+
throw new Error();
|
|
716
|
+
if (n > max2) {
|
|
717
|
+
return max2;
|
|
718
|
+
} else if (n < min2) {
|
|
719
|
+
return min2;
|
|
720
|
+
} else {
|
|
721
|
+
return n;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
339
724
|
|
|
340
|
-
// src/
|
|
725
|
+
// src/utils/promises.ts
|
|
341
726
|
function asPromise(promisable) {
|
|
342
727
|
return Promise.resolve(promisable);
|
|
343
728
|
}
|
|
@@ -355,7 +740,26 @@ function delayPromise(duration) {
|
|
|
355
740
|
return (result) => duration.promise().then(() => result);
|
|
356
741
|
}
|
|
357
742
|
|
|
358
|
-
// src/
|
|
743
|
+
// src/utils/random.ts
|
|
744
|
+
function randomInterval(min2, max2) {
|
|
745
|
+
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
746
|
+
}
|
|
747
|
+
function randomPercentage(min2, max2) {
|
|
748
|
+
return randomInterval(min2, max2) / 100;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// src/utils/records/entries.ts
|
|
752
|
+
function dictToEntries(obj) {
|
|
753
|
+
return Object.entries(obj);
|
|
754
|
+
}
|
|
755
|
+
function entriesToDict(entries) {
|
|
756
|
+
return Object.fromEntries(entries);
|
|
757
|
+
}
|
|
758
|
+
function mapEntries(dict, mapper) {
|
|
759
|
+
return entriesToDict(dictToEntries(dict).map((entry) => mapper(entry)));
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
// src/utils/records.ts
|
|
359
763
|
function dictToList(obj) {
|
|
360
764
|
return Object.keys(obj).map((key) => obj[key]);
|
|
361
765
|
}
|
|
@@ -366,50 +770,7 @@ function pick(o, keys) {
|
|
|
366
770
|
}, {});
|
|
367
771
|
}
|
|
368
772
|
|
|
369
|
-
// src/
|
|
370
|
-
function hashCode(str) {
|
|
371
|
-
let hash = 0;
|
|
372
|
-
for (let i = 0; i < str.length; ++i)
|
|
373
|
-
hash = Math.imul(31, hash) + str.charCodeAt(i);
|
|
374
|
-
return hash | 0;
|
|
375
|
-
}
|
|
376
|
-
function repeat(char, times) {
|
|
377
|
-
return times > 0 ? range(0, times - 1).map((_) => char).join("") : "";
|
|
378
|
-
}
|
|
379
|
-
function capitalizeWord(word) {
|
|
380
|
-
return word[0].toUpperCase() + word.substring(1).toLowerCase();
|
|
381
|
-
}
|
|
382
|
-
function splitWords(text, regEx = /\s+/) {
|
|
383
|
-
return text.split(regEx).filter((t) => t.length > 0);
|
|
384
|
-
}
|
|
385
|
-
function stringToNumber(s) {
|
|
386
|
-
if (isNullOrUndefined(s))
|
|
387
|
-
return null;
|
|
388
|
-
return Number(s);
|
|
389
|
-
}
|
|
390
|
-
function pad(str, n, char, where = "left") {
|
|
391
|
-
const length = ensureDefined(str).length;
|
|
392
|
-
if (length >= ensureDefined(n)) return str;
|
|
393
|
-
if (ensureDefined(char).length !== 1)
|
|
394
|
-
throw new Error("Illegal pad character");
|
|
395
|
-
const padding = repeat(char, n - length);
|
|
396
|
-
return (where === "left" ? padding : "") + str + (where === "right" ? padding : "");
|
|
397
|
-
}
|
|
398
|
-
function padLeft(str, n, char) {
|
|
399
|
-
return pad(str, n, char, "left");
|
|
400
|
-
}
|
|
401
|
-
function padRight(str, n, char) {
|
|
402
|
-
return pad(str, n, char, "right");
|
|
403
|
-
}
|
|
404
|
-
function ellipsis(str, maxLength, padChar, padWhere = "left") {
|
|
405
|
-
if (maxLength < 4)
|
|
406
|
-
throw new Error("Invalid argument maxLength");
|
|
407
|
-
if (str.length <= maxLength) {
|
|
408
|
-
return pad(str, maxLength, padChar, padWhere);
|
|
409
|
-
} else {
|
|
410
|
-
return str.substring(0, maxLength - 3) + "...";
|
|
411
|
-
}
|
|
412
|
-
}
|
|
773
|
+
// src/utils/strings/StringParts.ts
|
|
413
774
|
var StringParts = class _StringParts {
|
|
414
775
|
_parts;
|
|
415
776
|
constructor(...parts) {
|
|
@@ -432,8 +793,8 @@ var StringParts = class _StringParts {
|
|
|
432
793
|
return this._parts;
|
|
433
794
|
}
|
|
434
795
|
get tail() {
|
|
435
|
-
const [_first, ...
|
|
436
|
-
return
|
|
796
|
+
const [_first, ...tail2] = this.parts;
|
|
797
|
+
return tail2;
|
|
437
798
|
}
|
|
438
799
|
get first() {
|
|
439
800
|
return this._parts[0] ?? null;
|
|
@@ -461,179 +822,102 @@ var StringParts = class _StringParts {
|
|
|
461
822
|
return this.capitalizeEach().join("");
|
|
462
823
|
}
|
|
463
824
|
toHumanCase() {
|
|
464
|
-
return this.capitalizeFirst().join(" ");
|
|
465
|
-
}
|
|
466
|
-
join(separator) {
|
|
467
|
-
return this.parts.join(separator);
|
|
468
|
-
}
|
|
469
|
-
mergeWith({ parts: otherParts }) {
|
|
470
|
-
return new _StringParts(...this.parts, ...otherParts);
|
|
471
|
-
}
|
|
472
|
-
slice(start, end) {
|
|
473
|
-
return new _StringParts(...this.parts.slice(start, end));
|
|
474
|
-
}
|
|
475
|
-
splice(start, deleteCount, ...items) {
|
|
476
|
-
return new _StringParts(...this.parts.splice(start, deleteCount, ...items));
|
|
477
|
-
}
|
|
478
|
-
push(part) {
|
|
479
|
-
return new _StringParts(...this.parts, part);
|
|
480
|
-
}
|
|
481
|
-
shift(part) {
|
|
482
|
-
return new _StringParts(part, ...this.parts);
|
|
483
|
-
}
|
|
484
|
-
reverse() {
|
|
485
|
-
return new _StringParts(...this.parts.reverse());
|
|
486
|
-
}
|
|
487
|
-
static fromString = (s, separator = /\s+/g) => {
|
|
488
|
-
if (s === null || separator === null)
|
|
489
|
-
throw new Error("Invalid arguments");
|
|
490
|
-
return new _StringParts(...s.split(separator));
|
|
491
|
-
};
|
|
492
|
-
static fromParts = (...parts) => {
|
|
493
|
-
return new _StringParts(...parts);
|
|
494
|
-
};
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
// src/Lazy.ts
|
|
498
|
-
var Lazy = class _Lazy {
|
|
499
|
-
_value = void 0;
|
|
500
|
-
_initialized = false;
|
|
501
|
-
_generator;
|
|
502
|
-
constructor(generator) {
|
|
503
|
-
this._generator = ensureDefined(generator);
|
|
504
|
-
}
|
|
505
|
-
get value() {
|
|
506
|
-
return this._value;
|
|
507
|
-
}
|
|
508
|
-
getOrCreate() {
|
|
509
|
-
if (!this._initialized) {
|
|
510
|
-
this._value = this._generator();
|
|
511
|
-
this._initialized = true;
|
|
512
|
-
}
|
|
513
|
-
return this._value;
|
|
514
|
-
}
|
|
515
|
-
getOrThrow(errorMessage) {
|
|
516
|
-
if (!this._initialized)
|
|
517
|
-
throw new Error(errorMessage);
|
|
518
|
-
return this._value;
|
|
519
|
-
}
|
|
520
|
-
or(t) {
|
|
521
|
-
if (!this._initialized) {
|
|
522
|
-
return t;
|
|
523
|
-
} else {
|
|
524
|
-
return this._value;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
isPresent() {
|
|
528
|
-
return this._initialized;
|
|
529
|
-
}
|
|
530
|
-
isEmpty() {
|
|
531
|
-
return !this._initialized;
|
|
532
|
-
}
|
|
533
|
-
ifPresent(fn) {
|
|
534
|
-
if (this.isPresent()) {
|
|
535
|
-
fn(this._value);
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
ifEmpty(fn) {
|
|
539
|
-
if (this.isEmpty()) {
|
|
540
|
-
fn();
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
apply(fnPresent, fnEmpty) {
|
|
544
|
-
if (this.isPresent()) {
|
|
545
|
-
fnPresent(this._value);
|
|
546
|
-
} else {
|
|
547
|
-
fnEmpty();
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
static of(generator) {
|
|
551
|
-
return new _Lazy(generator);
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
// src/LazyAsync.ts
|
|
556
|
-
var LazyAsync = class _LazyAsync {
|
|
557
|
-
_promise = void 0;
|
|
558
|
-
_pending = false;
|
|
559
|
-
_resolvedValue = void 0;
|
|
560
|
-
_error = void 0;
|
|
561
|
-
_generator;
|
|
562
|
-
constructor(generator) {
|
|
563
|
-
this._generator = ensureDefined(generator);
|
|
564
|
-
}
|
|
565
|
-
getOrCreate() {
|
|
566
|
-
if (this.isEmpty()) {
|
|
567
|
-
this._pending = true;
|
|
568
|
-
this._promise = this._generator();
|
|
569
|
-
this._promise.then((value) => {
|
|
570
|
-
this._pending = false;
|
|
571
|
-
this._resolvedValue = value;
|
|
572
|
-
}, (err) => {
|
|
573
|
-
this._pending = false;
|
|
574
|
-
this._error = err;
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
return this._promise;
|
|
578
|
-
}
|
|
579
|
-
isPresent() {
|
|
580
|
-
return this._promise !== void 0;
|
|
581
|
-
}
|
|
582
|
-
isEmpty() {
|
|
583
|
-
return this._promise === void 0;
|
|
584
|
-
}
|
|
585
|
-
isPending() {
|
|
586
|
-
return this.isPresent() && this._pending === true;
|
|
587
|
-
}
|
|
588
|
-
isReady() {
|
|
589
|
-
return this.isPresent() && this._pending === false;
|
|
590
|
-
}
|
|
591
|
-
isResolved() {
|
|
592
|
-
return this.isReady() && this._error === void 0;
|
|
593
|
-
}
|
|
594
|
-
isError() {
|
|
595
|
-
return this.isReady() && this._error !== void 0;
|
|
596
|
-
}
|
|
597
|
-
ifPresent(fn) {
|
|
598
|
-
if (this.isPresent()) {
|
|
599
|
-
fn(this._promise);
|
|
600
|
-
}
|
|
825
|
+
return this.capitalizeFirst().join(" ");
|
|
601
826
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
fn();
|
|
605
|
-
}
|
|
827
|
+
join(separator) {
|
|
828
|
+
return this.parts.join(separator);
|
|
606
829
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
fn(this._promise);
|
|
610
|
-
}
|
|
830
|
+
mergeWith({ parts: otherParts }) {
|
|
831
|
+
return new _StringParts(...this.parts, ...otherParts);
|
|
611
832
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
fn(this._promise);
|
|
615
|
-
}
|
|
833
|
+
slice(start, end) {
|
|
834
|
+
return new _StringParts(...this.parts.slice(start, end));
|
|
616
835
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
fn(this._resolvedValue);
|
|
620
|
-
}
|
|
836
|
+
splice(start, deleteCount, ...items) {
|
|
837
|
+
return new _StringParts(...this.parts.splice(start, deleteCount, ...items));
|
|
621
838
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
fn(this._error);
|
|
625
|
-
}
|
|
839
|
+
push(part) {
|
|
840
|
+
return new _StringParts(...this.parts, part);
|
|
626
841
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
throw new Error(errorMessage);
|
|
630
|
-
return this._promise;
|
|
842
|
+
shift(part) {
|
|
843
|
+
return new _StringParts(part, ...this.parts);
|
|
631
844
|
}
|
|
632
|
-
|
|
633
|
-
return new
|
|
845
|
+
reverse() {
|
|
846
|
+
return new _StringParts(...this.parts.reverse());
|
|
634
847
|
}
|
|
848
|
+
static fromString = (s, separator = /\s+/g) => {
|
|
849
|
+
if (s === null || separator === null)
|
|
850
|
+
throw new Error("Invalid arguments");
|
|
851
|
+
return new _StringParts(...s.split(separator));
|
|
852
|
+
};
|
|
853
|
+
static fromParts = (...parts) => {
|
|
854
|
+
return new _StringParts(...parts);
|
|
855
|
+
};
|
|
635
856
|
};
|
|
636
857
|
|
|
858
|
+
// src/utils/strings.ts
|
|
859
|
+
function hashCode(str) {
|
|
860
|
+
let hash = 0;
|
|
861
|
+
for (let i = 0; i < str.length; ++i)
|
|
862
|
+
hash = Math.imul(31, hash) + str.charCodeAt(i);
|
|
863
|
+
return hash | 0;
|
|
864
|
+
}
|
|
865
|
+
function repeat(char, times) {
|
|
866
|
+
return times > 0 ? range(0, times - 1).map((_) => char).join("") : "";
|
|
867
|
+
}
|
|
868
|
+
function capitalizeWord(word) {
|
|
869
|
+
return word[0].toUpperCase() + word.substring(1).toLowerCase();
|
|
870
|
+
}
|
|
871
|
+
function splitWords(text, regEx = /\s+/) {
|
|
872
|
+
return text.split(regEx).filter((t) => t.length > 0);
|
|
873
|
+
}
|
|
874
|
+
function stringToNumber(s) {
|
|
875
|
+
if (isNullOrUndefined(s))
|
|
876
|
+
return null;
|
|
877
|
+
return Number(s);
|
|
878
|
+
}
|
|
879
|
+
function pad(str, n, char, where = "left") {
|
|
880
|
+
const length = ensureDefined(str).length;
|
|
881
|
+
if (length >= ensureDefined(n)) return str;
|
|
882
|
+
if (ensureDefined(char).length !== 1)
|
|
883
|
+
throw new Error("Illegal pad character");
|
|
884
|
+
const padding = repeat(char, n - length);
|
|
885
|
+
return (where === "left" ? padding : "") + str + (where === "right" ? padding : "");
|
|
886
|
+
}
|
|
887
|
+
function padLeft(str, n, char) {
|
|
888
|
+
return pad(str, n, char, "left");
|
|
889
|
+
}
|
|
890
|
+
function padRight(str, n, char) {
|
|
891
|
+
return pad(str, n, char, "right");
|
|
892
|
+
}
|
|
893
|
+
function ellipsis(str, maxLength, padChar, padWhere = "left") {
|
|
894
|
+
if (maxLength < 4)
|
|
895
|
+
throw new Error("Invalid argument maxLength");
|
|
896
|
+
if (str.length <= maxLength) {
|
|
897
|
+
return pad(str, maxLength, padChar, padWhere);
|
|
898
|
+
} else {
|
|
899
|
+
return str.substring(0, maxLength - 3) + "...";
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
function pluralize(n, singular, plural) {
|
|
903
|
+
if (!singular || !singular.length)
|
|
904
|
+
throw new Error();
|
|
905
|
+
if (n === 1)
|
|
906
|
+
return singular;
|
|
907
|
+
plural = plural ?? singular + "s";
|
|
908
|
+
const firstUppercase = singular.charAt(0) === singular.charAt(0).toUpperCase();
|
|
909
|
+
if (firstUppercase) {
|
|
910
|
+
const PLURAL = plural.toUpperCase();
|
|
911
|
+
const isAllUppercase = plural === PLURAL;
|
|
912
|
+
plural = isAllUppercase ? PLURAL : plural.charAt(0).toUpperCase() + plural.slice(1).toLowerCase();
|
|
913
|
+
}
|
|
914
|
+
return plural;
|
|
915
|
+
}
|
|
916
|
+
function wrapWithString(str, delimiter) {
|
|
917
|
+
return delimiter + str + delimiter;
|
|
918
|
+
}
|
|
919
|
+
var wrap = wrapWithString;
|
|
920
|
+
|
|
637
921
|
// src/time/TimeInstant.ts
|
|
638
922
|
var import_small_date = __toESM(require_lib());
|
|
639
923
|
|
|
@@ -755,101 +1039,6 @@ var TimeBase = class {
|
|
|
755
1039
|
}
|
|
756
1040
|
};
|
|
757
1041
|
|
|
758
|
-
// src/async/Deferred.ts
|
|
759
|
-
var DeferredCanceledError = class extends Error {
|
|
760
|
-
constructor() {
|
|
761
|
-
super("Execution canceled");
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
var Deferred = class {
|
|
765
|
-
_pending;
|
|
766
|
-
_internals;
|
|
767
|
-
get pending() {
|
|
768
|
-
return this._pending;
|
|
769
|
-
}
|
|
770
|
-
/** @deprecated: Use resolve, then and catch directly; use asPromise to return a promise type. */
|
|
771
|
-
get promise() {
|
|
772
|
-
return this._internals.promise;
|
|
773
|
-
}
|
|
774
|
-
constructor() {
|
|
775
|
-
this._pending = true;
|
|
776
|
-
this._internals = this.createInternals();
|
|
777
|
-
}
|
|
778
|
-
resolve(val) {
|
|
779
|
-
if (!this._pending)
|
|
780
|
-
throw new Error("Illegal state exception");
|
|
781
|
-
this.resolveIfPending(val);
|
|
782
|
-
}
|
|
783
|
-
reject(reason) {
|
|
784
|
-
if (!this._pending)
|
|
785
|
-
throw new Error("Illegal state exception");
|
|
786
|
-
this.rejectIfPending(reason);
|
|
787
|
-
}
|
|
788
|
-
cancel() {
|
|
789
|
-
if (!this._pending)
|
|
790
|
-
throw new Error("Illegal state exception");
|
|
791
|
-
this.cancelIfPending();
|
|
792
|
-
}
|
|
793
|
-
resolveIfPending(val) {
|
|
794
|
-
if (!this._pending)
|
|
795
|
-
return;
|
|
796
|
-
this._pending = false;
|
|
797
|
-
this._internals.resolve(val);
|
|
798
|
-
}
|
|
799
|
-
rejectIfPending(reason) {
|
|
800
|
-
if (!this._pending)
|
|
801
|
-
return;
|
|
802
|
-
this._pending = false;
|
|
803
|
-
this._internals.reject(reason);
|
|
804
|
-
}
|
|
805
|
-
cancelIfPending() {
|
|
806
|
-
if (!this._pending)
|
|
807
|
-
return;
|
|
808
|
-
this.reject(new DeferredCanceledError());
|
|
809
|
-
}
|
|
810
|
-
then(onFulfilled, onRejected) {
|
|
811
|
-
return this._internals.promise.then(onFulfilled, onRejected);
|
|
812
|
-
}
|
|
813
|
-
catch(onRejected) {
|
|
814
|
-
return this._internals.promise.catch(onRejected);
|
|
815
|
-
}
|
|
816
|
-
finally(onfinally) {
|
|
817
|
-
return this._internals.promise.finally(onfinally);
|
|
818
|
-
}
|
|
819
|
-
asPromise() {
|
|
820
|
-
return this;
|
|
821
|
-
}
|
|
822
|
-
asCancelablePromise() {
|
|
823
|
-
return this;
|
|
824
|
-
}
|
|
825
|
-
createInternals() {
|
|
826
|
-
let resolveSelf, rejectSelf;
|
|
827
|
-
const promise = new Promise((resolve, reject) => {
|
|
828
|
-
resolveSelf = resolve;
|
|
829
|
-
rejectSelf = reject;
|
|
830
|
-
});
|
|
831
|
-
return {
|
|
832
|
-
promise,
|
|
833
|
-
resolve: resolveSelf,
|
|
834
|
-
reject: rejectSelf
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
get [Symbol.toStringTag]() {
|
|
838
|
-
return "[object Deferred]";
|
|
839
|
-
}
|
|
840
|
-
};
|
|
841
|
-
var Deferred_default = Deferred;
|
|
842
|
-
|
|
843
|
-
// src/random/randomInterval.ts
|
|
844
|
-
function randomInterval(min2, max2) {
|
|
845
|
-
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
// src/random/randomPercentage.ts
|
|
849
|
-
function randomPercentage(min2, max2) {
|
|
850
|
-
return randomInterval(min2, max2) / 100;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
1042
|
// src/time/TimeDuration.ts
|
|
854
1043
|
var TimeDuration = class _TimeDuration extends TimeBase {
|
|
855
1044
|
constructor(value, unit) {
|
|
@@ -1514,10 +1703,6 @@ function isTimeInstant(x) {
|
|
|
1514
1703
|
}
|
|
1515
1704
|
var TimeInstant_default = TimeInstant;
|
|
1516
1705
|
|
|
1517
|
-
// src/utils/noop.ts
|
|
1518
|
-
function noop() {
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
1706
|
// src/Logger.ts
|
|
1522
1707
|
var LEVELS = ["log", "debug", "info", "warn", "error"];
|
|
1523
1708
|
var timestamp = () => TimeInstant_default.now().asTimeString();
|
|
@@ -1645,120 +1830,30 @@ var Optional = class _Optional {
|
|
|
1645
1830
|
return new _Optional(void 0);
|
|
1646
1831
|
}
|
|
1647
1832
|
static of(t) {
|
|
1648
|
-
if (isNullOrUndefined(t))
|
|
1649
|
-
throw new ErrorCannotInstantiatePresentOptionalWithEmptyValue();
|
|
1650
|
-
return new _Optional(t);
|
|
1651
|
-
}
|
|
1652
|
-
static ofNullable(t) {
|
|
1653
|
-
return new _Optional(t);
|
|
1654
|
-
}
|
|
1655
|
-
};
|
|
1656
|
-
var ErrorGetEmptyOptional = class extends Error {
|
|
1657
|
-
constructor() {
|
|
1658
|
-
super("Cannot retrieve a value from an EmptyOptional.");
|
|
1659
|
-
}
|
|
1660
|
-
};
|
|
1661
|
-
var ErrorSetEmptyOptional = class extends Error {
|
|
1662
|
-
constructor() {
|
|
1663
|
-
super("Cannot set a null or undefined value.");
|
|
1664
|
-
}
|
|
1665
|
-
};
|
|
1666
|
-
var ErrorCannotInstantiatePresentOptionalWithEmptyValue = class extends Error {
|
|
1667
|
-
constructor() {
|
|
1668
|
-
super("Cannot initialize a PresentOptional with a null or undefined value.");
|
|
1669
|
-
}
|
|
1670
|
-
};
|
|
1671
|
-
|
|
1672
|
-
// src/async/RateThrottler.ts
|
|
1673
|
-
var RateThrottler = class {
|
|
1674
|
-
constructor(_frequency) {
|
|
1675
|
-
this._frequency = _frequency;
|
|
1676
|
-
const initialOffset = this.cooldown.divideBy(_frequency.times);
|
|
1677
|
-
this._availableSlots = new Array(_frequency.times).fill(0).map((_, i) => TimeInstant.now().addMs(i * initialOffset.ms));
|
|
1678
|
-
this._waitingRequests = [];
|
|
1679
|
-
}
|
|
1680
|
-
_availableSlots;
|
|
1681
|
-
_waitingRequests;
|
|
1682
|
-
get cooldown() {
|
|
1683
|
-
return this._frequency.period;
|
|
1684
|
-
}
|
|
1685
|
-
async execute(fn) {
|
|
1686
|
-
const wrappedFn = async () => {
|
|
1687
|
-
const slot = this._availableSlots.shift();
|
|
1688
|
-
try {
|
|
1689
|
-
return slot.promise().then(() => fn());
|
|
1690
|
-
} finally {
|
|
1691
|
-
this._availableSlots.push(TimeInstant.now().addDuration(this.cooldown));
|
|
1692
|
-
if (this._waitingRequests.length > 0) this._waitingRequests.shift().resolve();
|
|
1693
|
-
}
|
|
1694
|
-
};
|
|
1695
|
-
if (this._availableSlots.length > 0) {
|
|
1696
|
-
return wrappedFn();
|
|
1697
|
-
} else {
|
|
1698
|
-
const waitingRequest = new Deferred_default();
|
|
1699
|
-
this._waitingRequests.push(waitingRequest);
|
|
1700
|
-
return waitingRequest.then(() => wrappedFn());
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
};
|
|
1704
|
-
|
|
1705
|
-
// src/async/Semaphore.ts
|
|
1706
|
-
var Semaphore = class {
|
|
1707
|
-
constructor(_availableSlots = 1) {
|
|
1708
|
-
this._availableSlots = _availableSlots;
|
|
1709
|
-
this._queuedRequests = [];
|
|
1710
|
-
}
|
|
1711
|
-
_queuedRequests;
|
|
1712
|
-
_inProgress = 0;
|
|
1713
|
-
async _awaitSlot() {
|
|
1714
|
-
if (this._availableSlots > 0) {
|
|
1715
|
-
this._availableSlots -= 1;
|
|
1716
|
-
this._inProgress += 1;
|
|
1717
|
-
return void 0;
|
|
1718
|
-
} else {
|
|
1719
|
-
const deferred = new Deferred_default();
|
|
1720
|
-
this._queuedRequests.push(deferred);
|
|
1721
|
-
return deferred.asPromise();
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
_releaseSlot() {
|
|
1725
|
-
const waitingSlotToResolve = this._queuedRequests.shift();
|
|
1726
|
-
if (waitingSlotToResolve) {
|
|
1727
|
-
waitingSlotToResolve.resolve();
|
|
1728
|
-
} else {
|
|
1729
|
-
this._availableSlots += 1;
|
|
1730
|
-
this._inProgress -= 1;
|
|
1731
|
-
}
|
|
1833
|
+
if (isNullOrUndefined(t))
|
|
1834
|
+
throw new ErrorCannotInstantiatePresentOptionalWithEmptyValue();
|
|
1835
|
+
return new _Optional(t);
|
|
1732
1836
|
}
|
|
1733
|
-
|
|
1734
|
-
return
|
|
1735
|
-
void cooldown.promise().then(() => this._releaseSlot());
|
|
1736
|
-
});
|
|
1837
|
+
static ofNullable(t) {
|
|
1838
|
+
return new _Optional(t);
|
|
1737
1839
|
}
|
|
1738
|
-
|
|
1739
|
-
|
|
1840
|
+
};
|
|
1841
|
+
var ErrorGetEmptyOptional = class extends Error {
|
|
1842
|
+
constructor() {
|
|
1843
|
+
super("Cannot retrieve a value from an EmptyOptional.");
|
|
1740
1844
|
}
|
|
1741
|
-
|
|
1742
|
-
|
|
1845
|
+
};
|
|
1846
|
+
var ErrorSetEmptyOptional = class extends Error {
|
|
1847
|
+
constructor() {
|
|
1848
|
+
super("Cannot set a null or undefined value.");
|
|
1743
1849
|
}
|
|
1744
|
-
|
|
1745
|
-
|
|
1850
|
+
};
|
|
1851
|
+
var ErrorCannotInstantiatePresentOptionalWithEmptyValue = class extends Error {
|
|
1852
|
+
constructor() {
|
|
1853
|
+
super("Cannot initialize a PresentOptional with a null or undefined value.");
|
|
1746
1854
|
}
|
|
1747
1855
|
};
|
|
1748
1856
|
|
|
1749
|
-
// src/utils/constant.ts
|
|
1750
|
-
function constant(v) {
|
|
1751
|
-
return () => v;
|
|
1752
|
-
}
|
|
1753
|
-
function identity(t) {
|
|
1754
|
-
return t;
|
|
1755
|
-
}
|
|
1756
|
-
var constantNull = constant(null);
|
|
1757
|
-
var constantTrue = constant(true);
|
|
1758
|
-
var constantFalse = constant(false);
|
|
1759
|
-
var constantZero = constant(0);
|
|
1760
|
-
var constantOne = constant(1);
|
|
1761
|
-
|
|
1762
1857
|
// src/sorting/ComparisonChain.ts
|
|
1763
1858
|
var defaultCompareValueOptions = {
|
|
1764
1859
|
nullsFirst: false,
|
|
@@ -2095,7 +2190,7 @@ var top = (fns, arr, n) => {
|
|
|
2095
2190
|
var bottom = (fns, arr, n) => {
|
|
2096
2191
|
return sort(fns, arr).slice(-Math.max(0, n)).reverse();
|
|
2097
2192
|
};
|
|
2098
|
-
var
|
|
2193
|
+
var first2 = (fns, arr) => {
|
|
2099
2194
|
return arr.length ? top(fns, arr, 1)[0] : null;
|
|
2100
2195
|
};
|
|
2101
2196
|
var last2 = (fns, arr) => {
|
|
@@ -2125,7 +2220,7 @@ function doCreateWithFunctions(fns) {
|
|
|
2125
2220
|
return bottom(fns, arr, n);
|
|
2126
2221
|
},
|
|
2127
2222
|
first: (arr) => {
|
|
2128
|
-
return
|
|
2223
|
+
return first2(fns, arr);
|
|
2129
2224
|
},
|
|
2130
2225
|
last: (arr) => {
|
|
2131
2226
|
return last2(fns, arr);
|
|
@@ -2207,258 +2302,6 @@ var TimeRange = class _TimeRange {
|
|
|
2207
2302
|
}
|
|
2208
2303
|
};
|
|
2209
2304
|
|
|
2210
|
-
// src/utils/bindThis.ts
|
|
2211
|
-
function bindThis(fn, _this) {
|
|
2212
|
-
return fn.bind(_this);
|
|
2213
|
-
}
|
|
2214
|
-
|
|
2215
|
-
// src/utils/entries.ts
|
|
2216
|
-
function dictToEntries(obj) {
|
|
2217
|
-
return Object.entries(obj);
|
|
2218
|
-
}
|
|
2219
|
-
function entriesToDict(entries) {
|
|
2220
|
-
return Object.fromEntries(entries);
|
|
2221
|
-
}
|
|
2222
|
-
function mapEntries(dict, mapper) {
|
|
2223
|
-
return entriesToDict(dictToEntries(dict).map((entry) => mapper(entry)));
|
|
2224
|
-
}
|
|
2225
|
-
|
|
2226
|
-
// src/utils/groupBy.ts
|
|
2227
|
-
function groupByString(arr, field) {
|
|
2228
|
-
return groupByStringWith(arr, (t) => t[field]);
|
|
2229
|
-
}
|
|
2230
|
-
function groupByNumber(arr, field) {
|
|
2231
|
-
return groupByNumberWith(arr, (t) => t[field]);
|
|
2232
|
-
}
|
|
2233
|
-
function groupBySymbol(arr, field) {
|
|
2234
|
-
return groupBySymbolWith(arr, (t) => t[field]);
|
|
2235
|
-
}
|
|
2236
|
-
function groupByStringWith(arr, getter) {
|
|
2237
|
-
return doGroupByWith(arr, getter);
|
|
2238
|
-
}
|
|
2239
|
-
function groupByNumberWith(arr, getter) {
|
|
2240
|
-
return doGroupByWith(arr, getter);
|
|
2241
|
-
}
|
|
2242
|
-
function groupBySymbolWith(arr, getter) {
|
|
2243
|
-
return doGroupByWith(arr, getter);
|
|
2244
|
-
}
|
|
2245
|
-
function doGroupByWith(arr, getter) {
|
|
2246
|
-
return arr.reduce((dict, cur) => {
|
|
2247
|
-
const key = getter(cur);
|
|
2248
|
-
if (key !== null && key !== void 0) {
|
|
2249
|
-
const arr2 = dict[key] ?? [];
|
|
2250
|
-
arr2.push(cur);
|
|
2251
|
-
dict[key] = arr2;
|
|
2252
|
-
}
|
|
2253
|
-
return dict;
|
|
2254
|
-
}, {});
|
|
2255
|
-
}
|
|
2256
|
-
|
|
2257
|
-
// src/utils/iff.ts
|
|
2258
|
-
function iff(firstPredicate, valueIfTrue) {
|
|
2259
|
-
if (firstPredicate === true || firstPredicate instanceof Function && firstPredicate() === true) {
|
|
2260
|
-
const ret = {
|
|
2261
|
-
elseIf: () => ret,
|
|
2262
|
-
otherwise: () => valueIfTrue
|
|
2263
|
-
};
|
|
2264
|
-
return ret;
|
|
2265
|
-
} else {
|
|
2266
|
-
const ret = {
|
|
2267
|
-
elseIf: (elseIf, valueIfElseIfTrue) => iff(elseIf, valueIfElseIfTrue),
|
|
2268
|
-
otherwise: (valueIfElse) => valueIfElse
|
|
2269
|
-
};
|
|
2270
|
-
return ret;
|
|
2271
|
-
}
|
|
2272
|
-
}
|
|
2273
|
-
|
|
2274
|
-
// src/utils/indexBy.ts
|
|
2275
|
-
function indexByString(arr, field) {
|
|
2276
|
-
return indexByStringWith(arr, (t) => t[field]);
|
|
2277
|
-
}
|
|
2278
|
-
function indexByNumber(arr, field) {
|
|
2279
|
-
return indexByNumberWith(arr, (t) => t[field]);
|
|
2280
|
-
}
|
|
2281
|
-
function indexBySymbol(arr, field) {
|
|
2282
|
-
return indexBySymbolWith(arr, (t) => t[field]);
|
|
2283
|
-
}
|
|
2284
|
-
function indexByStringWith(arr, getter) {
|
|
2285
|
-
return doIndexByWith(arr, getter);
|
|
2286
|
-
}
|
|
2287
|
-
function indexByNumberWith(arr, getter) {
|
|
2288
|
-
return doIndexByWith(arr, getter);
|
|
2289
|
-
}
|
|
2290
|
-
function indexBySymbolWith(arr, getter) {
|
|
2291
|
-
return doIndexByWith(arr, getter);
|
|
2292
|
-
}
|
|
2293
|
-
function doIndexByWith(arr, getter) {
|
|
2294
|
-
return arr.reduce((dict, cur) => {
|
|
2295
|
-
const key = getter(cur);
|
|
2296
|
-
if (key !== null && key !== void 0)
|
|
2297
|
-
dict[key] = cur;
|
|
2298
|
-
return dict;
|
|
2299
|
-
}, {});
|
|
2300
|
-
}
|
|
2301
|
-
|
|
2302
|
-
// src/utils/jsonCloneDeep.ts
|
|
2303
|
-
function jsonCloneDeep(a) {
|
|
2304
|
-
if (null === a || "object" !== typeof a) return a;
|
|
2305
|
-
if (a instanceof Date) {
|
|
2306
|
-
return new Date(a.getTime());
|
|
2307
|
-
} else if (a instanceof Array) {
|
|
2308
|
-
const copy = [];
|
|
2309
|
-
for (let i = 0, len = a.length; i < len; i++) {
|
|
2310
|
-
copy[i] = jsonCloneDeep(a[i]);
|
|
2311
|
-
}
|
|
2312
|
-
return copy;
|
|
2313
|
-
} else if (a instanceof Object) {
|
|
2314
|
-
const copy = {};
|
|
2315
|
-
for (let attr in a) {
|
|
2316
|
-
if (a.hasOwnProperty(attr))
|
|
2317
|
-
copy[attr] = jsonCloneDeep(a[attr]);
|
|
2318
|
-
}
|
|
2319
|
-
return copy;
|
|
2320
|
-
}
|
|
2321
|
-
throw new Error("Unable to copy obj! Its type isn't supported.");
|
|
2322
|
-
}
|
|
2323
|
-
|
|
2324
|
-
// src/utils/math.ts
|
|
2325
|
-
function clamp(n, min2, max2) {
|
|
2326
|
-
if (min2 === null || max2 === null || n === null || isNaN(min2) || isNaN(max2) || isNaN(n) || min2 > max2)
|
|
2327
|
-
throw new Error();
|
|
2328
|
-
if (n > max2) {
|
|
2329
|
-
return max2;
|
|
2330
|
-
} else if (n < min2) {
|
|
2331
|
-
return min2;
|
|
2332
|
-
} else {
|
|
2333
|
-
return n;
|
|
2334
|
-
}
|
|
2335
|
-
}
|
|
2336
|
-
function average(arr) {
|
|
2337
|
-
const f = 1 / arr.length;
|
|
2338
|
-
return arr.reduce((tot, cur) => tot + cur * f, 0);
|
|
2339
|
-
}
|
|
2340
|
-
function sum(arr) {
|
|
2341
|
-
return arr.reduce((tot, cur) => tot + cur, 0);
|
|
2342
|
-
}
|
|
2343
|
-
function sumBy(arr, getter) {
|
|
2344
|
-
return sum(arr.map(getter));
|
|
2345
|
-
}
|
|
2346
|
-
function min(arr) {
|
|
2347
|
-
if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
|
|
2348
|
-
return arr.reduce((min2, cur) => cur < min2 ? cur : min2);
|
|
2349
|
-
}
|
|
2350
|
-
function minBy(arr, getter) {
|
|
2351
|
-
return min(arr.map(getter));
|
|
2352
|
-
}
|
|
2353
|
-
function max(arr) {
|
|
2354
|
-
if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
|
|
2355
|
-
return arr.reduce((max2, cur) => cur > max2 ? cur : max2);
|
|
2356
|
-
}
|
|
2357
|
-
function maxBy(arr, getter) {
|
|
2358
|
-
return max(arr.map(getter));
|
|
2359
|
-
}
|
|
2360
|
-
|
|
2361
|
-
// src/utils/omit.ts
|
|
2362
|
-
function omit(o, ...keys) {
|
|
2363
|
-
return keys.reduce((obj, key) => {
|
|
2364
|
-
delete obj[key];
|
|
2365
|
-
return obj;
|
|
2366
|
-
}, { ...o });
|
|
2367
|
-
}
|
|
2368
|
-
|
|
2369
|
-
// src/utils/round.ts
|
|
2370
|
-
var roundModes = {
|
|
2371
|
-
"toNearest": Math.round,
|
|
2372
|
-
"toLower": Math.floor,
|
|
2373
|
-
"toUpper": Math.ceil,
|
|
2374
|
-
"towardsZero": (n) => n > 0 ? Math.floor(n) : Math.ceil(n),
|
|
2375
|
-
"awayFromZero": (n) => n > 0 ? Math.ceil(n) : Math.floor(n)
|
|
2376
|
-
};
|
|
2377
|
-
function round(n, precision = 0, mode = "toNearest") {
|
|
2378
|
-
const base = 10;
|
|
2379
|
-
const power = Math.pow(base, precision);
|
|
2380
|
-
return roundModes[mode](n * power) / power;
|
|
2381
|
-
}
|
|
2382
|
-
var roundToNearest = (n, precision = 0) => round(n, precision, "toNearest");
|
|
2383
|
-
var roundToLower = (n, precision = 0) => round(n, precision, "toLower");
|
|
2384
|
-
var roundToUpper = (n, precision = 0) => round(n, precision, "toUpper");
|
|
2385
|
-
var roundTowardsZero = (n, precision = 0) => round(n, precision, "towardsZero");
|
|
2386
|
-
var roundAwayFromZero = (n, precision = 0) => round(n, precision, "awayFromZero");
|
|
2387
|
-
|
|
2388
|
-
// src/utils/sortBy.ts
|
|
2389
|
-
function sortBy(keyOrGetter, direction = "ASC", nulls = "LAST") {
|
|
2390
|
-
const directionNum = direction === "ASC" ? -1 : 1;
|
|
2391
|
-
const nullsNum = nulls === "LAST" ? -1 : 1;
|
|
2392
|
-
const sortByNum = (a, b) => {
|
|
2393
|
-
if (a === b)
|
|
2394
|
-
return -1;
|
|
2395
|
-
const aDefined = !(a === null || a === void 0 || isNaN(a));
|
|
2396
|
-
const bDefined = !(b === null || b === void 0 || isNaN(b));
|
|
2397
|
-
if (!aDefined && !bDefined)
|
|
2398
|
-
return -1;
|
|
2399
|
-
if (aDefined !== bDefined)
|
|
2400
|
-
return nullsNum * (aDefined ? 1 : -1);
|
|
2401
|
-
return (a > b ? -1 : 1) * directionNum;
|
|
2402
|
-
};
|
|
2403
|
-
if (typeof keyOrGetter === "function") {
|
|
2404
|
-
return (a, b) => sortByNum(keyOrGetter(a), keyOrGetter(b));
|
|
2405
|
-
} else {
|
|
2406
|
-
return (a, b) => sortByNum(a[keyOrGetter], b[keyOrGetter]);
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
|
-
// src/utils/throttle.ts
|
|
2411
|
-
function throttle(fn, frequence) {
|
|
2412
|
-
const semaphore = new RateThrottler(frequence);
|
|
2413
|
-
return (...t) => {
|
|
2414
|
-
return semaphore.execute(async () => fn(...t));
|
|
2415
|
-
};
|
|
2416
|
-
}
|
|
2417
|
-
|
|
2418
|
-
// src/utils/uniqBy.ts
|
|
2419
|
-
function uniqBy(arr, getter) {
|
|
2420
|
-
return arr.reduce((dict, cur) => {
|
|
2421
|
-
const key = getter(cur);
|
|
2422
|
-
if (dict.keys.includes(key)) {
|
|
2423
|
-
return dict;
|
|
2424
|
-
} else {
|
|
2425
|
-
return {
|
|
2426
|
-
keys: [...dict.keys, key],
|
|
2427
|
-
values: [...dict.values, cur]
|
|
2428
|
-
};
|
|
2429
|
-
}
|
|
2430
|
-
}, { keys: [], values: [] }).values;
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2433
|
-
// src/utils/uniq.ts
|
|
2434
|
-
function uniq(arr) {
|
|
2435
|
-
return uniqBy(arr, identity);
|
|
2436
|
-
}
|
|
2437
|
-
|
|
2438
|
-
// src/utils/uniqByKey.ts
|
|
2439
|
-
function uniqByKey(arr, key) {
|
|
2440
|
-
return uniqBy(arr, (item) => item[key]);
|
|
2441
|
-
}
|
|
2442
|
-
|
|
2443
|
-
// src/utils/withTryCatch.ts
|
|
2444
|
-
function withTryCatch(fn) {
|
|
2445
|
-
try {
|
|
2446
|
-
return fn();
|
|
2447
|
-
} catch (e) {
|
|
2448
|
-
return asError(e);
|
|
2449
|
-
}
|
|
2450
|
-
}
|
|
2451
|
-
|
|
2452
|
-
// src/utils/withTryCatchAsync.ts
|
|
2453
|
-
async function withTryCatchAsync(fn) {
|
|
2454
|
-
return fn().catch((e) => asError(e));
|
|
2455
|
-
}
|
|
2456
|
-
|
|
2457
|
-
// src/utils/wrap.ts
|
|
2458
|
-
function wrap(str, delimiter) {
|
|
2459
|
-
return delimiter + str + delimiter;
|
|
2460
|
-
}
|
|
2461
|
-
|
|
2462
2305
|
// src/upgrade/errors.ts
|
|
2463
2306
|
var UnavailableUpgradeError = class extends Error {
|
|
2464
2307
|
constructor(data, from, to) {
|
|
@@ -2594,8 +2437,6 @@ export {
|
|
|
2594
2437
|
ErrorCannotInstantiatePresentOptionalWithEmptyValue,
|
|
2595
2438
|
ErrorGetEmptyOptional,
|
|
2596
2439
|
ErrorSetEmptyOptional,
|
|
2597
|
-
Lazy,
|
|
2598
|
-
LazyAsync,
|
|
2599
2440
|
Logger,
|
|
2600
2441
|
Optional,
|
|
2601
2442
|
RandomTimeDuration,
|
|
@@ -2640,7 +2481,10 @@ export {
|
|
|
2640
2481
|
extendArray,
|
|
2641
2482
|
extendArrayWith,
|
|
2642
2483
|
fill,
|
|
2484
|
+
first,
|
|
2643
2485
|
flatMapTruthys,
|
|
2486
|
+
groupByBoolean,
|
|
2487
|
+
groupByBooleanWith,
|
|
2644
2488
|
groupByNumber,
|
|
2645
2489
|
groupByNumberWith,
|
|
2646
2490
|
groupByString,
|
|
@@ -2688,10 +2532,12 @@ export {
|
|
|
2688
2532
|
multiplyBy,
|
|
2689
2533
|
noop,
|
|
2690
2534
|
omit,
|
|
2535
|
+
omitFromJsonObject,
|
|
2691
2536
|
pad,
|
|
2692
2537
|
padLeft,
|
|
2693
2538
|
padRight,
|
|
2694
2539
|
pick,
|
|
2540
|
+
pluralize,
|
|
2695
2541
|
promiseSequence,
|
|
2696
2542
|
randomInterval,
|
|
2697
2543
|
randomPercentage,
|
|
@@ -2704,12 +2550,12 @@ export {
|
|
|
2704
2550
|
roundToNearest,
|
|
2705
2551
|
roundToUpper,
|
|
2706
2552
|
roundTowardsZero,
|
|
2707
|
-
sortBy,
|
|
2708
2553
|
sortedArray,
|
|
2709
2554
|
splitWords,
|
|
2710
2555
|
stringToNumber,
|
|
2711
2556
|
sum,
|
|
2712
2557
|
sumBy,
|
|
2558
|
+
tail,
|
|
2713
2559
|
throttle,
|
|
2714
2560
|
tryToParseJson,
|
|
2715
2561
|
uniq,
|
|
@@ -2718,5 +2564,6 @@ export {
|
|
|
2718
2564
|
upsert,
|
|
2719
2565
|
withTryCatch,
|
|
2720
2566
|
withTryCatchAsync,
|
|
2721
|
-
wrap
|
|
2567
|
+
wrap,
|
|
2568
|
+
wrapWithString
|
|
2722
2569
|
};
|