@zelgadis87/utils-core 4.13.9 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/async/Deferred.d.ts +0 -2
- package/dist/async/_index.d.ts +0 -1
- package/dist/sorting/Sorter.d.ts +0 -11
- package/dist/sorting/_index.d.ts +0 -2
- package/dist/time/TimeDuration.d.ts +5 -17
- package/dist/time/TimeInstant.d.ts +4 -47
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/json.d.ts +0 -2
- package/dist/utils/random.d.ts +0 -4
- package/dist/utils/strings.d.ts +0 -2
- package/esbuild/index.cjs +43 -301
- package/esbuild/index.cjs.map +4 -4
- package/esbuild/index.mjs +43 -295
- package/esbuild/index.mjs.map +4 -4
- package/package.json +2 -2
- package/src/Logger.ts +1 -1
- package/src/async/Deferred.ts +0 -3
- package/src/async/_index.ts +0 -1
- package/src/sorting/Sorter.ts +0 -4
- package/src/sorting/_index.ts +1 -2
- package/src/time/RandomTimeDuration.ts +2 -2
- package/src/time/TimeDuration.ts +6 -37
- package/src/time/TimeInstant.ts +11 -80
- package/src/utils/css.ts +5 -1
- package/src/utils/json.ts +0 -2
- package/src/utils/random.ts +0 -6
- package/src/utils/strings.ts +0 -3
- /package/src/async/{CancelableDeferred.ts → CancelableDeferred.ts.off} +0 -0
- /package/src/sorting/{ComparisonChain.ts → ComparisonChain.ts.off} +0 -0
package/esbuild/index.cjs
CHANGED
|
@@ -171,7 +171,6 @@ var require_lib = __commonJS({
|
|
|
171
171
|
// src/index.ts
|
|
172
172
|
var src_exports = {};
|
|
173
173
|
__export(src_exports, {
|
|
174
|
-
ComparisonChain: () => ComparisonChain_default,
|
|
175
174
|
DataUpgrader: () => DataUpgrader,
|
|
176
175
|
Deferred: () => Deferred,
|
|
177
176
|
DeferredCanceledError: () => DeferredCanceledError,
|
|
@@ -187,7 +186,6 @@ __export(src_exports, {
|
|
|
187
186
|
RateThrottler: () => RateThrottler,
|
|
188
187
|
Semaphore: () => Semaphore,
|
|
189
188
|
Sorter: () => Sorter,
|
|
190
|
-
Sorting: () => Sorting,
|
|
191
189
|
StringParts: () => StringParts,
|
|
192
190
|
TimeDuration: () => TimeDuration,
|
|
193
191
|
TimeFrequency: () => TimeFrequency,
|
|
@@ -287,7 +285,6 @@ __export(src_exports, {
|
|
|
287
285
|
multiplyBy: () => multiplyBy,
|
|
288
286
|
noop: () => noop,
|
|
289
287
|
not: () => not,
|
|
290
|
-
omit: () => omit,
|
|
291
288
|
omitFromJsonObject: () => omitFromJsonObject,
|
|
292
289
|
or: () => or,
|
|
293
290
|
pad: () => pad,
|
|
@@ -300,9 +297,7 @@ __export(src_exports, {
|
|
|
300
297
|
pluralize: () => pluralize,
|
|
301
298
|
promiseSequence: () => promiseSequence,
|
|
302
299
|
randomId: () => randomId,
|
|
303
|
-
randomInterval: () => randomInterval,
|
|
304
300
|
randomNumberInInterval: () => randomNumberInInterval,
|
|
305
|
-
randomPercentage: () => randomPercentage,
|
|
306
301
|
range: () => range,
|
|
307
302
|
repeat: () => repeat,
|
|
308
303
|
reverse: () => reverse,
|
|
@@ -328,7 +323,6 @@ __export(src_exports, {
|
|
|
328
323
|
upsert: () => upsert,
|
|
329
324
|
withTryCatch: () => withTryCatch,
|
|
330
325
|
withTryCatchAsync: () => withTryCatchAsync,
|
|
331
|
-
wrap: () => wrap,
|
|
332
326
|
wrapWithString: () => wrapWithString,
|
|
333
327
|
xor: () => xor
|
|
334
328
|
});
|
|
@@ -346,10 +340,6 @@ var Deferred = class {
|
|
|
346
340
|
get pending() {
|
|
347
341
|
return this._pending;
|
|
348
342
|
}
|
|
349
|
-
/** @deprecated: Use resolve, then and catch directly; use asPromise to return a promise type. */
|
|
350
|
-
get promise() {
|
|
351
|
-
return this._internals.promise;
|
|
352
|
-
}
|
|
353
343
|
constructor() {
|
|
354
344
|
this._pending = true;
|
|
355
345
|
this._internals = this.createInternals();
|
|
@@ -844,7 +834,11 @@ function cssDeclarationRulesDictionaryToCss(syleDeclarationRulesForSelectorsProd
|
|
|
844
834
|
function cssSelectorDeclarationRulesDictionaryToCss(styleDeclarationRules, indent = 0) {
|
|
845
835
|
return Object.entries(styleDeclarationRules).map(([key, value]) => {
|
|
846
836
|
if (typeof value === "string") {
|
|
847
|
-
|
|
837
|
+
if (key.startsWith("--")) {
|
|
838
|
+
return repeat(tabulation, indent) + key + colon + space + value + semiColon;
|
|
839
|
+
} else {
|
|
840
|
+
return repeat(tabulation, indent) + pascalCaseToKebabCase(key) + colon + space + value + semiColon;
|
|
841
|
+
}
|
|
848
842
|
} else {
|
|
849
843
|
return repeat(tabulation, indent) + key + space + openBracket + newLine + cssSelectorDeclarationRulesDictionaryToCss(value, indent + 1).join(newLine) + newLine + repeat(tabulation, indent) + closeBracket;
|
|
850
844
|
}
|
|
@@ -933,7 +927,6 @@ function omitFromJsonObject(o, ...keys) {
|
|
|
933
927
|
return obj;
|
|
934
928
|
}, { ...o });
|
|
935
929
|
}
|
|
936
|
-
var omit = omitFromJsonObject;
|
|
937
930
|
|
|
938
931
|
// src/utils/numbers/round.ts
|
|
939
932
|
var roundModes = {
|
|
@@ -1060,8 +1053,6 @@ var NEVER = new Promise((_resolve) => {
|
|
|
1060
1053
|
});
|
|
1061
1054
|
|
|
1062
1055
|
// src/utils/random.ts
|
|
1063
|
-
var randomInterval = (min2, max2) => randomNumberInInterval(min2, max2);
|
|
1064
|
-
var randomPercentage = (min2, max2) => randomNumberInInterval(min2, max2) / 100;
|
|
1065
1056
|
function randomNumberInInterval(min2, max2) {
|
|
1066
1057
|
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
1067
1058
|
}
|
|
@@ -1248,7 +1239,6 @@ function pluralize(n, singular, plural) {
|
|
|
1248
1239
|
function wrapWithString(str, delimiter) {
|
|
1249
1240
|
return delimiter + str + delimiter;
|
|
1250
1241
|
}
|
|
1251
|
-
var wrap = wrapWithString;
|
|
1252
1242
|
|
|
1253
1243
|
// src/lazy/Lazy.ts
|
|
1254
1244
|
var Lazy = class _Lazy {
|
|
@@ -1531,10 +1521,6 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1531
1521
|
const nn = Math.min(n, this.getUnit(unit));
|
|
1532
1522
|
return super.removeUnits(nn, unit);
|
|
1533
1523
|
}
|
|
1534
|
-
/** @deprecated: Use multiplyBy instead **/
|
|
1535
|
-
multiply(times) {
|
|
1536
|
-
return this.multiplyBy(times);
|
|
1537
|
-
}
|
|
1538
1524
|
multiplyBy(times) {
|
|
1539
1525
|
ensureNonNegativeNumber(times, "times");
|
|
1540
1526
|
return _TimeDuration.ms(this.ms * times);
|
|
@@ -1566,12 +1552,6 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1566
1552
|
else
|
|
1567
1553
|
return "Some time ago";
|
|
1568
1554
|
}
|
|
1569
|
-
/**
|
|
1570
|
-
* @deprecated[2023-06] this method makes no sense, as durations are positive by default.
|
|
1571
|
-
*/
|
|
1572
|
-
absolute() {
|
|
1573
|
-
return this.ms < 0 ? new _TimeDuration(-this.ms, TimeUnit.MILLISECONDS) : this;
|
|
1574
|
-
}
|
|
1575
1555
|
interval(cb) {
|
|
1576
1556
|
return setInterval(cb, this.ms);
|
|
1577
1557
|
}
|
|
@@ -1636,10 +1616,6 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1636
1616
|
differenceFrom(other) {
|
|
1637
1617
|
return new _TimeDuration(Math.abs(this.ms - other.ms), TimeUnit.MILLISECONDS);
|
|
1638
1618
|
}
|
|
1639
|
-
/** @deprecated: Use fromNow instead **/
|
|
1640
|
-
addCurrentTime() {
|
|
1641
|
-
return this.fromNow();
|
|
1642
|
-
}
|
|
1643
1619
|
isGreaterThan(other) {
|
|
1644
1620
|
return this.ms > other.ms;
|
|
1645
1621
|
}
|
|
@@ -1695,11 +1671,11 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1695
1671
|
static compare(a, b) {
|
|
1696
1672
|
return a.compareTo(b);
|
|
1697
1673
|
}
|
|
1698
|
-
static ms =
|
|
1699
|
-
static seconds =
|
|
1700
|
-
static minutes =
|
|
1701
|
-
static hours =
|
|
1702
|
-
static days =
|
|
1674
|
+
static ms = (value) => new _TimeDuration(value, TimeUnit.MILLISECONDS);
|
|
1675
|
+
static seconds = (value) => new _TimeDuration(value, TimeUnit.SECONDS);
|
|
1676
|
+
static minutes = (value) => new _TimeDuration(value, TimeUnit.MINUTES);
|
|
1677
|
+
static hours = (value) => new _TimeDuration(value, TimeUnit.HOURS);
|
|
1678
|
+
static days = (value) => new _TimeDuration(value, TimeUnit.DAYS);
|
|
1703
1679
|
static shamefulUnref = (ms) => {
|
|
1704
1680
|
if (ms instanceof _TimeDuration) {
|
|
1705
1681
|
return ms.ms;
|
|
@@ -1741,13 +1717,6 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1741
1717
|
return _TimeDuration.ms(ms);
|
|
1742
1718
|
}
|
|
1743
1719
|
};
|
|
1744
|
-
function durationConstructor(unit) {
|
|
1745
|
-
return (a, b) => {
|
|
1746
|
-
const aMs = unit.toMs(a);
|
|
1747
|
-
const bMs = b ? unit.toMs(b) : aMs;
|
|
1748
|
-
return TimeDuration.fromMs(randomInterval(aMs, bMs));
|
|
1749
|
-
};
|
|
1750
|
-
}
|
|
1751
1720
|
function isAllowedTimeDuration(t) {
|
|
1752
1721
|
return typeof t === "number" && t > 0 || t instanceof TimeDuration;
|
|
1753
1722
|
}
|
|
@@ -1909,6 +1878,9 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1909
1878
|
distanceFromNow() {
|
|
1910
1879
|
return TimeDuration_default.fromMs(Math.abs(this.ms - Date.now()));
|
|
1911
1880
|
}
|
|
1881
|
+
distanceFromUnixTimestamp(timestamp2) {
|
|
1882
|
+
return TimeDuration_default.ms(this.ms - timestamp2);
|
|
1883
|
+
}
|
|
1912
1884
|
timeLeftFrom(instant) {
|
|
1913
1885
|
const distance = this.ms - instant.ms;
|
|
1914
1886
|
return TimeDuration_default.fromMs(Math.max(distance, 0));
|
|
@@ -1942,30 +1914,16 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1942
1914
|
return this.timeLeftFromNow().cancelableDelay(cb);
|
|
1943
1915
|
}
|
|
1944
1916
|
ensureInTheFuture() {
|
|
1945
|
-
if (!this.isInTheFuture)
|
|
1946
|
-
throw new Error("Instant is in the
|
|
1917
|
+
if (!this.isInTheFuture())
|
|
1918
|
+
throw new Error("Instant is not in the future");
|
|
1947
1919
|
}
|
|
1948
1920
|
ensureInThePast() {
|
|
1949
|
-
if (!this.isInThePast)
|
|
1950
|
-
throw new Error("Instant is in the
|
|
1921
|
+
if (!this.isInThePast())
|
|
1922
|
+
throw new Error("Instant is not in the past");
|
|
1951
1923
|
}
|
|
1952
1924
|
isToday() {
|
|
1953
1925
|
return Math.floor(this.days) === Math.floor(_TimeInstant.now().days);
|
|
1954
1926
|
}
|
|
1955
|
-
/**
|
|
1956
|
-
* @returns the time as HH:mm:ss
|
|
1957
|
-
* @deprecated [2024-12-11] this method is too ambigous and should be removed.
|
|
1958
|
-
*/
|
|
1959
|
-
asTimeString() {
|
|
1960
|
-
return this.format("HH:mm:ss");
|
|
1961
|
-
}
|
|
1962
|
-
/**
|
|
1963
|
-
* @returns the date as dd/MM/yyyy
|
|
1964
|
-
* @deprecated [2024-12-11] this method is too ambigous and should be removed.
|
|
1965
|
-
*/
|
|
1966
|
-
asDateString() {
|
|
1967
|
-
return this.format("dd/MM/yyyy");
|
|
1968
|
-
}
|
|
1969
1927
|
/**
|
|
1970
1928
|
* Formats this instant using the given pattern. The pattern can contain the following tokens:
|
|
1971
1929
|
*
|
|
@@ -2017,8 +1975,7 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
2017
1975
|
return this.format('yyyy-MM-dd"T"HH:mm:ss.SSS"Z"', { timeZone: "UTC" });
|
|
2018
1976
|
}
|
|
2019
1977
|
/**
|
|
2020
|
-
* @returns this instant, in a human readable format. The format COULD change in the future, do NOT use this method for consistent outputs.
|
|
2021
|
-
* @deprecated [2024-12-11] this method is too broad and ambigous and should be removed.
|
|
1978
|
+
* @returns this instant, in a human readable format, containing both the date and the time. The format COULD change in the future, do NOT use this method for consistent outputs.
|
|
2022
1979
|
*/
|
|
2023
1980
|
asHumanTimestamp() {
|
|
2024
1981
|
return this.format("yyyy-MM-dd HH:mm:ss");
|
|
@@ -2032,28 +1989,16 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
2032
1989
|
toDateUTC() {
|
|
2033
1990
|
return new Date(this.ms + (/* @__PURE__ */ new Date()).getTimezoneOffset() * 60 * 1e3);
|
|
2034
1991
|
}
|
|
2035
|
-
/**
|
|
2036
|
-
* @deprecated use {@link TimeInstant#isInThePast2} instead.
|
|
2037
|
-
*/
|
|
2038
|
-
get isInThePast() {
|
|
2039
|
-
return this.ms < Date.now();
|
|
2040
|
-
}
|
|
2041
|
-
/**
|
|
2042
|
-
* @deprecated use {@link TimeInstant#isInTheFuture2} instead.
|
|
2043
|
-
*/
|
|
2044
|
-
get isInTheFuture() {
|
|
2045
|
-
return this.ms > Date.now();
|
|
2046
|
-
}
|
|
2047
1992
|
/**
|
|
2048
1993
|
* @returns true if the instant is in the past, false otherwise
|
|
2049
1994
|
*/
|
|
2050
|
-
|
|
1995
|
+
isInThePast() {
|
|
2051
1996
|
return this.ms < Date.now();
|
|
2052
1997
|
}
|
|
2053
1998
|
/**
|
|
2054
1999
|
* @returns true if the instant is in the future, false otherwise
|
|
2055
2000
|
*/
|
|
2056
|
-
|
|
2001
|
+
isInTheFuture() {
|
|
2057
2002
|
return this.ms > Date.now();
|
|
2058
2003
|
}
|
|
2059
2004
|
isAfter(other) {
|
|
@@ -2071,30 +2016,6 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
2071
2016
|
return 1;
|
|
2072
2017
|
}
|
|
2073
2018
|
}
|
|
2074
|
-
/**
|
|
2075
|
-
* @deprecated: Use {@link distanceFromNow} instead
|
|
2076
|
-
*/
|
|
2077
|
-
// TODO[2023-07-04, Deprecated]: Remove this method in a future version
|
|
2078
|
-
fromNow() {
|
|
2079
|
-
return TimeDuration_default.ms(this.ms - Date.now());
|
|
2080
|
-
}
|
|
2081
|
-
/**
|
|
2082
|
-
* @deprecated: Use {@link distanceFrom} instead
|
|
2083
|
-
*/
|
|
2084
|
-
// TODO[2023-07-04, Deprecated]: Remove this method in a future version
|
|
2085
|
-
from(instant) {
|
|
2086
|
-
return TimeDuration_default.ms(this.ms - instant.ms);
|
|
2087
|
-
}
|
|
2088
|
-
/**
|
|
2089
|
-
* @deprecated: Use {@link distanceFromUnixTimestamp} instead
|
|
2090
|
-
*/
|
|
2091
|
-
// TODO[2023-07-04, Deprecated]: Remove this method in a future version
|
|
2092
|
-
fromTimestamp(timestamp2) {
|
|
2093
|
-
return TimeDuration_default.ms(this.ms - timestamp2);
|
|
2094
|
-
}
|
|
2095
|
-
distanceFromUnixTimestamp(timestamp2) {
|
|
2096
|
-
return TimeDuration_default.ms(this.ms - timestamp2);
|
|
2097
|
-
}
|
|
2098
2019
|
atTime(parameters) {
|
|
2099
2020
|
return _TimeInstant.fromParameters(parameters, this);
|
|
2100
2021
|
}
|
|
@@ -2128,15 +2049,6 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
2128
2049
|
static builder() {
|
|
2129
2050
|
return timeInstantBuilder();
|
|
2130
2051
|
}
|
|
2131
|
-
/**
|
|
2132
|
-
* @deprecated[19/07/2023] Use {@link fromParameters} instead.
|
|
2133
|
-
*/
|
|
2134
|
-
static fromUnits({ date, month, year, hours, minutes, seconds }) {
|
|
2135
|
-
const dt = Date.UTC(year, month - 1, date, hours ?? 0, minutes ?? 0, seconds ?? 0);
|
|
2136
|
-
if (isNaN(dt))
|
|
2137
|
-
throw new Error(`Unparseable date: ${date}, ${month}, ${year}, ${hours ?? "-"}, ${minutes ?? "-"}, ${seconds ?? "-"}`);
|
|
2138
|
-
return _TimeInstant.fromUnixTimestamp(dt);
|
|
2139
|
-
}
|
|
2140
2052
|
static fromIso8601(str) {
|
|
2141
2053
|
return _TimeInstant.fromUnixTimestamp(new Date(str).getTime());
|
|
2142
2054
|
}
|
|
@@ -2148,9 +2060,6 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
2148
2060
|
static now() {
|
|
2149
2061
|
return _TimeInstant.fromUnixTimestamp(Date.now());
|
|
2150
2062
|
}
|
|
2151
|
-
static get currentTimeStamp() {
|
|
2152
|
-
return Date.now();
|
|
2153
|
-
}
|
|
2154
2063
|
static compare(a, b) {
|
|
2155
2064
|
return a.compareTo(b);
|
|
2156
2065
|
}
|
|
@@ -2221,7 +2130,7 @@ var TimeInstant_default = TimeInstant;
|
|
|
2221
2130
|
|
|
2222
2131
|
// src/Logger.ts
|
|
2223
2132
|
var LEVELS = ["log", "debug", "info", "warn", "error"];
|
|
2224
|
-
var timestamp = () => TimeInstant_default.now().
|
|
2133
|
+
var timestamp = () => TimeInstant_default.now().format("HH:mm:ss");
|
|
2225
2134
|
var Logger = class {
|
|
2226
2135
|
constructor(name, args) {
|
|
2227
2136
|
this.name = name;
|
|
@@ -2377,166 +2286,6 @@ var ErrorCannotInstantiatePresentOptionalWithEmptyValue = class extends Error {
|
|
|
2377
2286
|
}
|
|
2378
2287
|
};
|
|
2379
2288
|
|
|
2380
|
-
// src/sorting/ComparisonChain.ts
|
|
2381
|
-
var defaultCompareValueOptions = {
|
|
2382
|
-
nullsFirst: false,
|
|
2383
|
-
direction: "ASC"
|
|
2384
|
-
};
|
|
2385
|
-
function looseOptionsToStrict(x) {
|
|
2386
|
-
return { ...defaultCompareValueOptions, ...typeof x === "string" ? { direction: x } : x };
|
|
2387
|
-
}
|
|
2388
|
-
function compareValues(a, b, options) {
|
|
2389
|
-
if (a === b)
|
|
2390
|
-
return 0;
|
|
2391
|
-
const nullA = a === null || a === void 0;
|
|
2392
|
-
const nullB = b === null || b === void 0;
|
|
2393
|
-
if (nullA && nullB)
|
|
2394
|
-
return 0;
|
|
2395
|
-
if (nullA !== nullB)
|
|
2396
|
-
return nullA === options.nullsFirst ? -1 : 1;
|
|
2397
|
-
return a < b ? -1 : 1;
|
|
2398
|
-
}
|
|
2399
|
-
function compareFunction(fn, options) {
|
|
2400
|
-
return (a, b) => applyDirection(compareValues(fn(a), fn(b), options), options.direction);
|
|
2401
|
-
}
|
|
2402
|
-
function applyDirection(res, direction) {
|
|
2403
|
-
return res * (direction === "ASC" ? 1 : -1);
|
|
2404
|
-
}
|
|
2405
|
-
function compareUsingGetter(getter, options) {
|
|
2406
|
-
return compareFunction(getter, looseOptionsToStrict(options));
|
|
2407
|
-
}
|
|
2408
|
-
function compareUsingField(field, options) {
|
|
2409
|
-
return compareFunction((t) => t[field], looseOptionsToStrict(options));
|
|
2410
|
-
}
|
|
2411
|
-
function compareUsingNaturalOrder(options) {
|
|
2412
|
-
return compareFunction(identity, looseOptionsToStrict(options));
|
|
2413
|
-
}
|
|
2414
|
-
function compareStrings(options) {
|
|
2415
|
-
return compareFunction((t) => options?.ignoreCase === true ? t.toLowerCase() : t, looseOptionsToStrict(options));
|
|
2416
|
-
}
|
|
2417
|
-
function compareBooleans(options) {
|
|
2418
|
-
const opts = { ...defaultCompareValueOptions, ...options };
|
|
2419
|
-
const fn = (a, b) => {
|
|
2420
|
-
if (a === b)
|
|
2421
|
-
return 0;
|
|
2422
|
-
if (isNullOrUndefined(a))
|
|
2423
|
-
return opts.nullsFirst ? -1 : 1;
|
|
2424
|
-
if (isNullOrUndefined(b))
|
|
2425
|
-
return opts.nullsFirst ? 1 : -1;
|
|
2426
|
-
return a === true && opts.truesFirst || a === false && !opts.truesFirst ? -1 : 1;
|
|
2427
|
-
};
|
|
2428
|
-
return (a, b) => applyDirection(fn(a, b), opts.direction);
|
|
2429
|
-
}
|
|
2430
|
-
function compareUsingFunction(fn) {
|
|
2431
|
-
return fn;
|
|
2432
|
-
}
|
|
2433
|
-
function compareUsingSet(arr) {
|
|
2434
|
-
const fn = (a, b) => {
|
|
2435
|
-
if (a === b)
|
|
2436
|
-
return 0;
|
|
2437
|
-
const aIncluded = isDefined(a) && arr.includes(a);
|
|
2438
|
-
const bIncluded = isDefined(b) && arr.includes(b);
|
|
2439
|
-
if (aIncluded === bIncluded) {
|
|
2440
|
-
return 0;
|
|
2441
|
-
} else {
|
|
2442
|
-
return aIncluded ? -1 : 1;
|
|
2443
|
-
}
|
|
2444
|
-
};
|
|
2445
|
-
return fn;
|
|
2446
|
-
}
|
|
2447
|
-
function compareUsingArray(arr) {
|
|
2448
|
-
const fn = (a, b) => {
|
|
2449
|
-
if (a === b)
|
|
2450
|
-
return 0;
|
|
2451
|
-
const aIncluded = isDefined(a) && arr.includes(a);
|
|
2452
|
-
const bIncluded = isDefined(b) && arr.includes(b);
|
|
2453
|
-
if (!aIncluded && !bIncluded) {
|
|
2454
|
-
return 0;
|
|
2455
|
-
} else if (aIncluded && bIncluded) {
|
|
2456
|
-
return arr.indexOf(a) < arr.indexOf(b) ? -1 : 1;
|
|
2457
|
-
} else {
|
|
2458
|
-
return aIncluded ? -1 : 1;
|
|
2459
|
-
}
|
|
2460
|
-
};
|
|
2461
|
-
return fn;
|
|
2462
|
-
}
|
|
2463
|
-
function reverse2(fn) {
|
|
2464
|
-
return (a, b) => fn(a, b) * -1;
|
|
2465
|
-
}
|
|
2466
|
-
var ComparisonChain = class _ComparisonChain {
|
|
2467
|
-
constructor(_fns, _reversed = false) {
|
|
2468
|
-
this._fns = _fns;
|
|
2469
|
-
this._reversed = _reversed;
|
|
2470
|
-
}
|
|
2471
|
-
compare = (a, b) => {
|
|
2472
|
-
return this.doCompare(a, b) * (this._reversed ? -1 : 1);
|
|
2473
|
-
};
|
|
2474
|
-
sort = (arr) => {
|
|
2475
|
-
return [...arr].sort(this.compare);
|
|
2476
|
-
};
|
|
2477
|
-
then(getFn) {
|
|
2478
|
-
const cmp = getFn(createCompare());
|
|
2479
|
-
return this.thenBy(cmp);
|
|
2480
|
-
}
|
|
2481
|
-
thenBy(cmp) {
|
|
2482
|
-
return new _ComparisonChain([...this._fns, getComparisonFunction(cmp)]);
|
|
2483
|
-
}
|
|
2484
|
-
thenChain(transform, getFn) {
|
|
2485
|
-
const cmp = getFn(createCompare());
|
|
2486
|
-
return this.thenChainBy(transform, cmp);
|
|
2487
|
-
}
|
|
2488
|
-
thenChainBy(transform, cmp) {
|
|
2489
|
-
return new _ComparisonChain([...this._fns, applyTransformationBeforeComparison(transform, getComparisonFunction(cmp))]);
|
|
2490
|
-
}
|
|
2491
|
-
reversed() {
|
|
2492
|
-
return new _ComparisonChain([...this._fns], !this._reversed);
|
|
2493
|
-
}
|
|
2494
|
-
doCompare(a, b) {
|
|
2495
|
-
return this._fns.reduce((ret, fn) => {
|
|
2496
|
-
return ret !== 0 ? ret : fn(a, b);
|
|
2497
|
-
}, 0);
|
|
2498
|
-
}
|
|
2499
|
-
static create() {
|
|
2500
|
-
return {
|
|
2501
|
-
using: (getFn) => {
|
|
2502
|
-
return new _ComparisonChain([]).then(getFn);
|
|
2503
|
-
},
|
|
2504
|
-
usingTransformation: (transform, getFn) => {
|
|
2505
|
-
return new _ComparisonChain([]).thenChain(transform, getFn);
|
|
2506
|
-
}
|
|
2507
|
-
};
|
|
2508
|
-
}
|
|
2509
|
-
static createWith(getFn) {
|
|
2510
|
-
return this.create().using(getFn);
|
|
2511
|
-
}
|
|
2512
|
-
static createWithTransformation(transform, getFn) {
|
|
2513
|
-
return this.create().usingTransformation(transform, getFn);
|
|
2514
|
-
}
|
|
2515
|
-
};
|
|
2516
|
-
var ComparisonChain_default = ComparisonChain;
|
|
2517
|
-
function createCompare() {
|
|
2518
|
-
return {
|
|
2519
|
-
compareUsingGetter,
|
|
2520
|
-
compareUsingField,
|
|
2521
|
-
compareUsingStrings: compareStrings,
|
|
2522
|
-
compareUsingStringsIgnoringCase: (options) => compareStrings({ ...looseOptionsToStrict(options), ignoreCase: true }),
|
|
2523
|
-
compareUsingBooleans: compareBooleans,
|
|
2524
|
-
compareUsingNumbers: compareUsingNaturalOrder,
|
|
2525
|
-
compareUsingDates: compareUsingNaturalOrder,
|
|
2526
|
-
compareUsingFunction,
|
|
2527
|
-
placeFirst: (arr) => compareUsingSet(arr),
|
|
2528
|
-
placeFirstInOrder: (arr) => compareUsingArray(arr),
|
|
2529
|
-
placeLast: (arr) => reverse2(compareUsingSet(arr)),
|
|
2530
|
-
placeLastInOrder: (arr) => reverse2(compareUsingArray([...arr].reverse()))
|
|
2531
|
-
};
|
|
2532
|
-
}
|
|
2533
|
-
function applyTransformationBeforeComparison(transform, fn) {
|
|
2534
|
-
return (a, b) => fn(transform(a), transform(b));
|
|
2535
|
-
}
|
|
2536
|
-
function getComparisonFunction(arg) {
|
|
2537
|
-
return arg instanceof ComparisonChain ? arg.compare : arg;
|
|
2538
|
-
}
|
|
2539
|
-
|
|
2540
2289
|
// src/sorting/Sorter.ts
|
|
2541
2290
|
var defaultCompareValuesOptions = {
|
|
2542
2291
|
nullsFirst: false
|
|
@@ -2546,7 +2295,7 @@ var defaultCompareFunctionOptions = {
|
|
|
2546
2295
|
direction: "ASC"
|
|
2547
2296
|
};
|
|
2548
2297
|
var naturalOrderComparison = (a, b) => a < b ? -1 : 1;
|
|
2549
|
-
function
|
|
2298
|
+
function compareValues(a, b, cmp, { nullsFirst }) {
|
|
2550
2299
|
if (a === b)
|
|
2551
2300
|
return 0;
|
|
2552
2301
|
const nullA = isNullOrUndefined(a);
|
|
@@ -2557,16 +2306,16 @@ function compareValues2(a, b, cmp, { nullsFirst }) {
|
|
|
2557
2306
|
return nullA === nullsFirst ? -1 : 1;
|
|
2558
2307
|
return cmp(a, b);
|
|
2559
2308
|
}
|
|
2560
|
-
function
|
|
2561
|
-
return (a, b) =>
|
|
2309
|
+
function compareFunction(fn, cmp, { nullsFirst, direction }) {
|
|
2310
|
+
return (a, b) => applyDirection(compareValues(fn(a), fn(b), cmp, { nullsFirst }), direction);
|
|
2562
2311
|
}
|
|
2563
|
-
function
|
|
2312
|
+
function applyDirection(res, direction) {
|
|
2564
2313
|
return res * (direction === "ASC" ? 1 : -1);
|
|
2565
2314
|
}
|
|
2566
2315
|
function combine(f, g) {
|
|
2567
2316
|
return (t) => g(f(t));
|
|
2568
2317
|
}
|
|
2569
|
-
function
|
|
2318
|
+
function reverse2(fn) {
|
|
2570
2319
|
return (a, b) => fn(a, b) * -1;
|
|
2571
2320
|
}
|
|
2572
2321
|
var chain = (fns, cmpFn) => {
|
|
@@ -2576,34 +2325,34 @@ var transformAndChain = (fns, transform, cmpFn) => {
|
|
|
2576
2325
|
const fn = (a, b) => cmpFn(transform(a), transform(b));
|
|
2577
2326
|
return chain(fns, fn);
|
|
2578
2327
|
};
|
|
2579
|
-
var
|
|
2328
|
+
var compareStrings = (fns, transform, options = {}) => {
|
|
2580
2329
|
const { nullsFirst, direction, ignoreCase } = { ...defaultStringComparisonOptions, ...options };
|
|
2581
2330
|
if (ignoreCase)
|
|
2582
2331
|
transform = combine(transform, (t) => t.toLowerCase());
|
|
2583
|
-
return chain(fns,
|
|
2332
|
+
return chain(fns, compareFunction(transform, naturalOrderComparison, { nullsFirst, direction }));
|
|
2584
2333
|
};
|
|
2585
2334
|
var compareNumbers = (fns, transform, options = {}) => {
|
|
2586
2335
|
const { nullsFirst, direction } = { ...defaultNumberComparisonOptions, ...options };
|
|
2587
|
-
return chain(fns,
|
|
2336
|
+
return chain(fns, compareFunction(transform, naturalOrderComparison, { nullsFirst, direction }));
|
|
2588
2337
|
};
|
|
2589
2338
|
var compareDates = (fns, transform, options = {}) => {
|
|
2590
2339
|
const { nullsFirst, direction } = { ...defaultDateComparisonOptions, ...options };
|
|
2591
|
-
return chain(fns,
|
|
2340
|
+
return chain(fns, compareFunction(transform, naturalOrderComparison, { nullsFirst, direction }));
|
|
2592
2341
|
};
|
|
2593
2342
|
var compareTimeInstants = (fns, transform, options = {}) => {
|
|
2594
2343
|
const { nullsFirst, direction } = { ...defaultTimeInstantComparisonOptions, ...options };
|
|
2595
|
-
return chain(fns,
|
|
2344
|
+
return chain(fns, compareFunction(transform, (a, b) => a.isBefore(b) ? -1 : 1, { nullsFirst, direction }));
|
|
2596
2345
|
};
|
|
2597
2346
|
var compareTimeDurations = (fns, transform, options = {}) => {
|
|
2598
2347
|
const { nullsFirst, direction } = { ...defaultTimeDurationComparisonOptions, ...options };
|
|
2599
|
-
return chain(fns,
|
|
2348
|
+
return chain(fns, compareFunction(transform, (a, b) => a.isLessThan(b) ? -1 : 1, { nullsFirst, direction }));
|
|
2600
2349
|
};
|
|
2601
|
-
var
|
|
2350
|
+
var compareBooleans = (fns, transform, options) => {
|
|
2602
2351
|
const { nullsFirst, truesFirst } = { ...defaultBooleanComparisonOptions, ...options };
|
|
2603
|
-
return chain(fns,
|
|
2352
|
+
return chain(fns, compareFunction(transform, naturalOrderComparison, { nullsFirst, direction: truesFirst ? "DESC" : "ASC" }));
|
|
2604
2353
|
};
|
|
2605
2354
|
var prioritizeSet = (fns, transform, set, reversed = false) => {
|
|
2606
|
-
return
|
|
2355
|
+
return compareBooleans(fns, (t) => {
|
|
2607
2356
|
const r = transform(t);
|
|
2608
2357
|
return isDefined(r) && set.includes(r);
|
|
2609
2358
|
}, { truesFirst: !reversed, nullsFirst: false });
|
|
@@ -2667,25 +2416,25 @@ var next = (fns, transform) => {
|
|
|
2667
2416
|
const retForStrings = {
|
|
2668
2417
|
...retAsUsing,
|
|
2669
2418
|
inLexographicalOrder(opts = {}) {
|
|
2670
|
-
return
|
|
2419
|
+
return compareStrings(fns, transform, { direction: "ASC", ignoreCase: false, ...opts });
|
|
2671
2420
|
},
|
|
2672
2421
|
inLexographicalOrderIgnoringCase(opts = {}) {
|
|
2673
|
-
return
|
|
2422
|
+
return compareStrings(fns, transform, { direction: "ASC", ignoreCase: true, ...opts });
|
|
2674
2423
|
},
|
|
2675
2424
|
inReverseLexographicalOrder(opts = {}) {
|
|
2676
|
-
return
|
|
2425
|
+
return compareStrings(fns, transform, { direction: "DESC", ignoreCase: false, ...opts });
|
|
2677
2426
|
},
|
|
2678
2427
|
inReverseLexographicalOrderIgnoringCase(opts = {}) {
|
|
2679
|
-
return
|
|
2428
|
+
return compareStrings(fns, transform, { direction: "DESC", ignoreCase: true, ...opts });
|
|
2680
2429
|
}
|
|
2681
2430
|
};
|
|
2682
2431
|
const retForBooleans = {
|
|
2683
2432
|
...retAsUsing,
|
|
2684
2433
|
truesFirst(opts = {}) {
|
|
2685
|
-
return
|
|
2434
|
+
return compareBooleans(fns, transform, { truesFirst: true, ...opts });
|
|
2686
2435
|
},
|
|
2687
2436
|
falsesFirst(opts = {}) {
|
|
2688
|
-
return
|
|
2437
|
+
return compareBooleans(fns, transform, { truesFirst: false, ...opts });
|
|
2689
2438
|
}
|
|
2690
2439
|
};
|
|
2691
2440
|
const retForDates = {
|
|
@@ -2771,7 +2520,7 @@ function doCreateWithFunctions(fns) {
|
|
|
2771
2520
|
return next(fns, identity);
|
|
2772
2521
|
},
|
|
2773
2522
|
reversed() {
|
|
2774
|
-
return doCreateWithFunctions([...fns.map(
|
|
2523
|
+
return doCreateWithFunctions([...fns.map(reverse2)]);
|
|
2775
2524
|
},
|
|
2776
2525
|
compare: (a, b) => {
|
|
2777
2526
|
return compare(fns, a, b);
|
|
@@ -2807,12 +2556,11 @@ var Sorter = {
|
|
|
2807
2556
|
first: (arr, builder) => builder(doCreateEmpty()).first(arr),
|
|
2808
2557
|
last: (arr, builder) => builder(doCreateEmpty()).last(arr)
|
|
2809
2558
|
};
|
|
2810
|
-
var Sorting = Sorter;
|
|
2811
2559
|
|
|
2812
2560
|
// src/time/RandomTimeDuration.ts
|
|
2813
2561
|
function randomize(unit) {
|
|
2814
2562
|
return (a, b) => {
|
|
2815
|
-
return TimeDuration_default.fromMs(
|
|
2563
|
+
return TimeDuration_default.fromMs(randomNumberInInterval(unit.toMs(a), unit.toMs(b)));
|
|
2816
2564
|
};
|
|
2817
2565
|
}
|
|
2818
2566
|
var RandomTimeDuration = class {
|
|
@@ -2996,7 +2744,6 @@ function isUpgradable(obj) {
|
|
|
2996
2744
|
}
|
|
2997
2745
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2998
2746
|
0 && (module.exports = {
|
|
2999
|
-
ComparisonChain,
|
|
3000
2747
|
DataUpgrader,
|
|
3001
2748
|
Deferred,
|
|
3002
2749
|
DeferredCanceledError,
|
|
@@ -3012,7 +2759,6 @@ function isUpgradable(obj) {
|
|
|
3012
2759
|
RateThrottler,
|
|
3013
2760
|
Semaphore,
|
|
3014
2761
|
Sorter,
|
|
3015
|
-
Sorting,
|
|
3016
2762
|
StringParts,
|
|
3017
2763
|
TimeDuration,
|
|
3018
2764
|
TimeFrequency,
|
|
@@ -3112,7 +2858,6 @@ function isUpgradable(obj) {
|
|
|
3112
2858
|
multiplyBy,
|
|
3113
2859
|
noop,
|
|
3114
2860
|
not,
|
|
3115
|
-
omit,
|
|
3116
2861
|
omitFromJsonObject,
|
|
3117
2862
|
or,
|
|
3118
2863
|
pad,
|
|
@@ -3125,9 +2870,7 @@ function isUpgradable(obj) {
|
|
|
3125
2870
|
pluralize,
|
|
3126
2871
|
promiseSequence,
|
|
3127
2872
|
randomId,
|
|
3128
|
-
randomInterval,
|
|
3129
2873
|
randomNumberInInterval,
|
|
3130
|
-
randomPercentage,
|
|
3131
2874
|
range,
|
|
3132
2875
|
repeat,
|
|
3133
2876
|
reverse,
|
|
@@ -3153,7 +2896,6 @@ function isUpgradable(obj) {
|
|
|
3153
2896
|
upsert,
|
|
3154
2897
|
withTryCatch,
|
|
3155
2898
|
withTryCatchAsync,
|
|
3156
|
-
wrap,
|
|
3157
2899
|
wrapWithString,
|
|
3158
2900
|
xor
|
|
3159
2901
|
});
|