@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.mjs
CHANGED
|
@@ -174,10 +174,6 @@ var Deferred = class {
|
|
|
174
174
|
get pending() {
|
|
175
175
|
return this._pending;
|
|
176
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
177
|
constructor() {
|
|
182
178
|
this._pending = true;
|
|
183
179
|
this._internals = this.createInternals();
|
|
@@ -672,7 +668,11 @@ function cssDeclarationRulesDictionaryToCss(syleDeclarationRulesForSelectorsProd
|
|
|
672
668
|
function cssSelectorDeclarationRulesDictionaryToCss(styleDeclarationRules, indent = 0) {
|
|
673
669
|
return Object.entries(styleDeclarationRules).map(([key, value]) => {
|
|
674
670
|
if (typeof value === "string") {
|
|
675
|
-
|
|
671
|
+
if (key.startsWith("--")) {
|
|
672
|
+
return repeat(tabulation, indent) + key + colon + space + value + semiColon;
|
|
673
|
+
} else {
|
|
674
|
+
return repeat(tabulation, indent) + pascalCaseToKebabCase(key) + colon + space + value + semiColon;
|
|
675
|
+
}
|
|
676
676
|
} else {
|
|
677
677
|
return repeat(tabulation, indent) + key + space + openBracket + newLine + cssSelectorDeclarationRulesDictionaryToCss(value, indent + 1).join(newLine) + newLine + repeat(tabulation, indent) + closeBracket;
|
|
678
678
|
}
|
|
@@ -761,7 +761,6 @@ function omitFromJsonObject(o, ...keys) {
|
|
|
761
761
|
return obj;
|
|
762
762
|
}, { ...o });
|
|
763
763
|
}
|
|
764
|
-
var omit = omitFromJsonObject;
|
|
765
764
|
|
|
766
765
|
// src/utils/numbers/round.ts
|
|
767
766
|
var roundModes = {
|
|
@@ -888,8 +887,6 @@ var NEVER = new Promise((_resolve) => {
|
|
|
888
887
|
});
|
|
889
888
|
|
|
890
889
|
// src/utils/random.ts
|
|
891
|
-
var randomInterval = (min2, max2) => randomNumberInInterval(min2, max2);
|
|
892
|
-
var randomPercentage = (min2, max2) => randomNumberInInterval(min2, max2) / 100;
|
|
893
890
|
function randomNumberInInterval(min2, max2) {
|
|
894
891
|
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
895
892
|
}
|
|
@@ -1076,7 +1073,6 @@ function pluralize(n, singular, plural) {
|
|
|
1076
1073
|
function wrapWithString(str, delimiter) {
|
|
1077
1074
|
return delimiter + str + delimiter;
|
|
1078
1075
|
}
|
|
1079
|
-
var wrap = wrapWithString;
|
|
1080
1076
|
|
|
1081
1077
|
// src/lazy/Lazy.ts
|
|
1082
1078
|
var Lazy = class _Lazy {
|
|
@@ -1359,10 +1355,6 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1359
1355
|
const nn = Math.min(n, this.getUnit(unit));
|
|
1360
1356
|
return super.removeUnits(nn, unit);
|
|
1361
1357
|
}
|
|
1362
|
-
/** @deprecated: Use multiplyBy instead **/
|
|
1363
|
-
multiply(times) {
|
|
1364
|
-
return this.multiplyBy(times);
|
|
1365
|
-
}
|
|
1366
1358
|
multiplyBy(times) {
|
|
1367
1359
|
ensureNonNegativeNumber(times, "times");
|
|
1368
1360
|
return _TimeDuration.ms(this.ms * times);
|
|
@@ -1394,12 +1386,6 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1394
1386
|
else
|
|
1395
1387
|
return "Some time ago";
|
|
1396
1388
|
}
|
|
1397
|
-
/**
|
|
1398
|
-
* @deprecated[2023-06] this method makes no sense, as durations are positive by default.
|
|
1399
|
-
*/
|
|
1400
|
-
absolute() {
|
|
1401
|
-
return this.ms < 0 ? new _TimeDuration(-this.ms, TimeUnit.MILLISECONDS) : this;
|
|
1402
|
-
}
|
|
1403
1389
|
interval(cb) {
|
|
1404
1390
|
return setInterval(cb, this.ms);
|
|
1405
1391
|
}
|
|
@@ -1464,10 +1450,6 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1464
1450
|
differenceFrom(other) {
|
|
1465
1451
|
return new _TimeDuration(Math.abs(this.ms - other.ms), TimeUnit.MILLISECONDS);
|
|
1466
1452
|
}
|
|
1467
|
-
/** @deprecated: Use fromNow instead **/
|
|
1468
|
-
addCurrentTime() {
|
|
1469
|
-
return this.fromNow();
|
|
1470
|
-
}
|
|
1471
1453
|
isGreaterThan(other) {
|
|
1472
1454
|
return this.ms > other.ms;
|
|
1473
1455
|
}
|
|
@@ -1523,11 +1505,11 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1523
1505
|
static compare(a, b) {
|
|
1524
1506
|
return a.compareTo(b);
|
|
1525
1507
|
}
|
|
1526
|
-
static ms =
|
|
1527
|
-
static seconds =
|
|
1528
|
-
static minutes =
|
|
1529
|
-
static hours =
|
|
1530
|
-
static days =
|
|
1508
|
+
static ms = (value) => new _TimeDuration(value, TimeUnit.MILLISECONDS);
|
|
1509
|
+
static seconds = (value) => new _TimeDuration(value, TimeUnit.SECONDS);
|
|
1510
|
+
static minutes = (value) => new _TimeDuration(value, TimeUnit.MINUTES);
|
|
1511
|
+
static hours = (value) => new _TimeDuration(value, TimeUnit.HOURS);
|
|
1512
|
+
static days = (value) => new _TimeDuration(value, TimeUnit.DAYS);
|
|
1531
1513
|
static shamefulUnref = (ms) => {
|
|
1532
1514
|
if (ms instanceof _TimeDuration) {
|
|
1533
1515
|
return ms.ms;
|
|
@@ -1569,13 +1551,6 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1569
1551
|
return _TimeDuration.ms(ms);
|
|
1570
1552
|
}
|
|
1571
1553
|
};
|
|
1572
|
-
function durationConstructor(unit) {
|
|
1573
|
-
return (a, b) => {
|
|
1574
|
-
const aMs = unit.toMs(a);
|
|
1575
|
-
const bMs = b ? unit.toMs(b) : aMs;
|
|
1576
|
-
return TimeDuration.fromMs(randomInterval(aMs, bMs));
|
|
1577
|
-
};
|
|
1578
|
-
}
|
|
1579
1554
|
function isAllowedTimeDuration(t) {
|
|
1580
1555
|
return typeof t === "number" && t > 0 || t instanceof TimeDuration;
|
|
1581
1556
|
}
|
|
@@ -1737,6 +1712,9 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1737
1712
|
distanceFromNow() {
|
|
1738
1713
|
return TimeDuration_default.fromMs(Math.abs(this.ms - Date.now()));
|
|
1739
1714
|
}
|
|
1715
|
+
distanceFromUnixTimestamp(timestamp2) {
|
|
1716
|
+
return TimeDuration_default.ms(this.ms - timestamp2);
|
|
1717
|
+
}
|
|
1740
1718
|
timeLeftFrom(instant) {
|
|
1741
1719
|
const distance = this.ms - instant.ms;
|
|
1742
1720
|
return TimeDuration_default.fromMs(Math.max(distance, 0));
|
|
@@ -1770,30 +1748,16 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1770
1748
|
return this.timeLeftFromNow().cancelableDelay(cb);
|
|
1771
1749
|
}
|
|
1772
1750
|
ensureInTheFuture() {
|
|
1773
|
-
if (!this.isInTheFuture)
|
|
1774
|
-
throw new Error("Instant is in the
|
|
1751
|
+
if (!this.isInTheFuture())
|
|
1752
|
+
throw new Error("Instant is not in the future");
|
|
1775
1753
|
}
|
|
1776
1754
|
ensureInThePast() {
|
|
1777
|
-
if (!this.isInThePast)
|
|
1778
|
-
throw new Error("Instant is in the
|
|
1755
|
+
if (!this.isInThePast())
|
|
1756
|
+
throw new Error("Instant is not in the past");
|
|
1779
1757
|
}
|
|
1780
1758
|
isToday() {
|
|
1781
1759
|
return Math.floor(this.days) === Math.floor(_TimeInstant.now().days);
|
|
1782
1760
|
}
|
|
1783
|
-
/**
|
|
1784
|
-
* @returns the time as HH:mm:ss
|
|
1785
|
-
* @deprecated [2024-12-11] this method is too ambigous and should be removed.
|
|
1786
|
-
*/
|
|
1787
|
-
asTimeString() {
|
|
1788
|
-
return this.format("HH:mm:ss");
|
|
1789
|
-
}
|
|
1790
|
-
/**
|
|
1791
|
-
* @returns the date as dd/MM/yyyy
|
|
1792
|
-
* @deprecated [2024-12-11] this method is too ambigous and should be removed.
|
|
1793
|
-
*/
|
|
1794
|
-
asDateString() {
|
|
1795
|
-
return this.format("dd/MM/yyyy");
|
|
1796
|
-
}
|
|
1797
1761
|
/**
|
|
1798
1762
|
* Formats this instant using the given pattern. The pattern can contain the following tokens:
|
|
1799
1763
|
*
|
|
@@ -1845,8 +1809,7 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1845
1809
|
return this.format('yyyy-MM-dd"T"HH:mm:ss.SSS"Z"', { timeZone: "UTC" });
|
|
1846
1810
|
}
|
|
1847
1811
|
/**
|
|
1848
|
-
* @returns this instant, in a human readable format. The format COULD change in the future, do NOT use this method for consistent outputs.
|
|
1849
|
-
* @deprecated [2024-12-11] this method is too broad and ambigous and should be removed.
|
|
1812
|
+
* @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.
|
|
1850
1813
|
*/
|
|
1851
1814
|
asHumanTimestamp() {
|
|
1852
1815
|
return this.format("yyyy-MM-dd HH:mm:ss");
|
|
@@ -1860,28 +1823,16 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1860
1823
|
toDateUTC() {
|
|
1861
1824
|
return new Date(this.ms + (/* @__PURE__ */ new Date()).getTimezoneOffset() * 60 * 1e3);
|
|
1862
1825
|
}
|
|
1863
|
-
/**
|
|
1864
|
-
* @deprecated use {@link TimeInstant#isInThePast2} instead.
|
|
1865
|
-
*/
|
|
1866
|
-
get isInThePast() {
|
|
1867
|
-
return this.ms < Date.now();
|
|
1868
|
-
}
|
|
1869
|
-
/**
|
|
1870
|
-
* @deprecated use {@link TimeInstant#isInTheFuture2} instead.
|
|
1871
|
-
*/
|
|
1872
|
-
get isInTheFuture() {
|
|
1873
|
-
return this.ms > Date.now();
|
|
1874
|
-
}
|
|
1875
1826
|
/**
|
|
1876
1827
|
* @returns true if the instant is in the past, false otherwise
|
|
1877
1828
|
*/
|
|
1878
|
-
|
|
1829
|
+
isInThePast() {
|
|
1879
1830
|
return this.ms < Date.now();
|
|
1880
1831
|
}
|
|
1881
1832
|
/**
|
|
1882
1833
|
* @returns true if the instant is in the future, false otherwise
|
|
1883
1834
|
*/
|
|
1884
|
-
|
|
1835
|
+
isInTheFuture() {
|
|
1885
1836
|
return this.ms > Date.now();
|
|
1886
1837
|
}
|
|
1887
1838
|
isAfter(other) {
|
|
@@ -1899,30 +1850,6 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1899
1850
|
return 1;
|
|
1900
1851
|
}
|
|
1901
1852
|
}
|
|
1902
|
-
/**
|
|
1903
|
-
* @deprecated: Use {@link distanceFromNow} instead
|
|
1904
|
-
*/
|
|
1905
|
-
// TODO[2023-07-04, Deprecated]: Remove this method in a future version
|
|
1906
|
-
fromNow() {
|
|
1907
|
-
return TimeDuration_default.ms(this.ms - Date.now());
|
|
1908
|
-
}
|
|
1909
|
-
/**
|
|
1910
|
-
* @deprecated: Use {@link distanceFrom} instead
|
|
1911
|
-
*/
|
|
1912
|
-
// TODO[2023-07-04, Deprecated]: Remove this method in a future version
|
|
1913
|
-
from(instant) {
|
|
1914
|
-
return TimeDuration_default.ms(this.ms - instant.ms);
|
|
1915
|
-
}
|
|
1916
|
-
/**
|
|
1917
|
-
* @deprecated: Use {@link distanceFromUnixTimestamp} instead
|
|
1918
|
-
*/
|
|
1919
|
-
// TODO[2023-07-04, Deprecated]: Remove this method in a future version
|
|
1920
|
-
fromTimestamp(timestamp2) {
|
|
1921
|
-
return TimeDuration_default.ms(this.ms - timestamp2);
|
|
1922
|
-
}
|
|
1923
|
-
distanceFromUnixTimestamp(timestamp2) {
|
|
1924
|
-
return TimeDuration_default.ms(this.ms - timestamp2);
|
|
1925
|
-
}
|
|
1926
1853
|
atTime(parameters) {
|
|
1927
1854
|
return _TimeInstant.fromParameters(parameters, this);
|
|
1928
1855
|
}
|
|
@@ -1956,15 +1883,6 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1956
1883
|
static builder() {
|
|
1957
1884
|
return timeInstantBuilder();
|
|
1958
1885
|
}
|
|
1959
|
-
/**
|
|
1960
|
-
* @deprecated[19/07/2023] Use {@link fromParameters} instead.
|
|
1961
|
-
*/
|
|
1962
|
-
static fromUnits({ date, month, year, hours, minutes, seconds }) {
|
|
1963
|
-
const dt = Date.UTC(year, month - 1, date, hours ?? 0, minutes ?? 0, seconds ?? 0);
|
|
1964
|
-
if (isNaN(dt))
|
|
1965
|
-
throw new Error(`Unparseable date: ${date}, ${month}, ${year}, ${hours ?? "-"}, ${minutes ?? "-"}, ${seconds ?? "-"}`);
|
|
1966
|
-
return _TimeInstant.fromUnixTimestamp(dt);
|
|
1967
|
-
}
|
|
1968
1886
|
static fromIso8601(str) {
|
|
1969
1887
|
return _TimeInstant.fromUnixTimestamp(new Date(str).getTime());
|
|
1970
1888
|
}
|
|
@@ -1976,9 +1894,6 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
1976
1894
|
static now() {
|
|
1977
1895
|
return _TimeInstant.fromUnixTimestamp(Date.now());
|
|
1978
1896
|
}
|
|
1979
|
-
static get currentTimeStamp() {
|
|
1980
|
-
return Date.now();
|
|
1981
|
-
}
|
|
1982
1897
|
static compare(a, b) {
|
|
1983
1898
|
return a.compareTo(b);
|
|
1984
1899
|
}
|
|
@@ -2049,7 +1964,7 @@ var TimeInstant_default = TimeInstant;
|
|
|
2049
1964
|
|
|
2050
1965
|
// src/Logger.ts
|
|
2051
1966
|
var LEVELS = ["log", "debug", "info", "warn", "error"];
|
|
2052
|
-
var timestamp = () => TimeInstant_default.now().
|
|
1967
|
+
var timestamp = () => TimeInstant_default.now().format("HH:mm:ss");
|
|
2053
1968
|
var Logger = class {
|
|
2054
1969
|
constructor(name, args) {
|
|
2055
1970
|
this.name = name;
|
|
@@ -2205,166 +2120,6 @@ var ErrorCannotInstantiatePresentOptionalWithEmptyValue = class extends Error {
|
|
|
2205
2120
|
}
|
|
2206
2121
|
};
|
|
2207
2122
|
|
|
2208
|
-
// src/sorting/ComparisonChain.ts
|
|
2209
|
-
var defaultCompareValueOptions = {
|
|
2210
|
-
nullsFirst: false,
|
|
2211
|
-
direction: "ASC"
|
|
2212
|
-
};
|
|
2213
|
-
function looseOptionsToStrict(x) {
|
|
2214
|
-
return { ...defaultCompareValueOptions, ...typeof x === "string" ? { direction: x } : x };
|
|
2215
|
-
}
|
|
2216
|
-
function compareValues(a, b, options) {
|
|
2217
|
-
if (a === b)
|
|
2218
|
-
return 0;
|
|
2219
|
-
const nullA = a === null || a === void 0;
|
|
2220
|
-
const nullB = b === null || b === void 0;
|
|
2221
|
-
if (nullA && nullB)
|
|
2222
|
-
return 0;
|
|
2223
|
-
if (nullA !== nullB)
|
|
2224
|
-
return nullA === options.nullsFirst ? -1 : 1;
|
|
2225
|
-
return a < b ? -1 : 1;
|
|
2226
|
-
}
|
|
2227
|
-
function compareFunction(fn, options) {
|
|
2228
|
-
return (a, b) => applyDirection(compareValues(fn(a), fn(b), options), options.direction);
|
|
2229
|
-
}
|
|
2230
|
-
function applyDirection(res, direction) {
|
|
2231
|
-
return res * (direction === "ASC" ? 1 : -1);
|
|
2232
|
-
}
|
|
2233
|
-
function compareUsingGetter(getter, options) {
|
|
2234
|
-
return compareFunction(getter, looseOptionsToStrict(options));
|
|
2235
|
-
}
|
|
2236
|
-
function compareUsingField(field, options) {
|
|
2237
|
-
return compareFunction((t) => t[field], looseOptionsToStrict(options));
|
|
2238
|
-
}
|
|
2239
|
-
function compareUsingNaturalOrder(options) {
|
|
2240
|
-
return compareFunction(identity, looseOptionsToStrict(options));
|
|
2241
|
-
}
|
|
2242
|
-
function compareStrings(options) {
|
|
2243
|
-
return compareFunction((t) => options?.ignoreCase === true ? t.toLowerCase() : t, looseOptionsToStrict(options));
|
|
2244
|
-
}
|
|
2245
|
-
function compareBooleans(options) {
|
|
2246
|
-
const opts = { ...defaultCompareValueOptions, ...options };
|
|
2247
|
-
const fn = (a, b) => {
|
|
2248
|
-
if (a === b)
|
|
2249
|
-
return 0;
|
|
2250
|
-
if (isNullOrUndefined(a))
|
|
2251
|
-
return opts.nullsFirst ? -1 : 1;
|
|
2252
|
-
if (isNullOrUndefined(b))
|
|
2253
|
-
return opts.nullsFirst ? 1 : -1;
|
|
2254
|
-
return a === true && opts.truesFirst || a === false && !opts.truesFirst ? -1 : 1;
|
|
2255
|
-
};
|
|
2256
|
-
return (a, b) => applyDirection(fn(a, b), opts.direction);
|
|
2257
|
-
}
|
|
2258
|
-
function compareUsingFunction(fn) {
|
|
2259
|
-
return fn;
|
|
2260
|
-
}
|
|
2261
|
-
function compareUsingSet(arr) {
|
|
2262
|
-
const fn = (a, b) => {
|
|
2263
|
-
if (a === b)
|
|
2264
|
-
return 0;
|
|
2265
|
-
const aIncluded = isDefined(a) && arr.includes(a);
|
|
2266
|
-
const bIncluded = isDefined(b) && arr.includes(b);
|
|
2267
|
-
if (aIncluded === bIncluded) {
|
|
2268
|
-
return 0;
|
|
2269
|
-
} else {
|
|
2270
|
-
return aIncluded ? -1 : 1;
|
|
2271
|
-
}
|
|
2272
|
-
};
|
|
2273
|
-
return fn;
|
|
2274
|
-
}
|
|
2275
|
-
function compareUsingArray(arr) {
|
|
2276
|
-
const fn = (a, b) => {
|
|
2277
|
-
if (a === b)
|
|
2278
|
-
return 0;
|
|
2279
|
-
const aIncluded = isDefined(a) && arr.includes(a);
|
|
2280
|
-
const bIncluded = isDefined(b) && arr.includes(b);
|
|
2281
|
-
if (!aIncluded && !bIncluded) {
|
|
2282
|
-
return 0;
|
|
2283
|
-
} else if (aIncluded && bIncluded) {
|
|
2284
|
-
return arr.indexOf(a) < arr.indexOf(b) ? -1 : 1;
|
|
2285
|
-
} else {
|
|
2286
|
-
return aIncluded ? -1 : 1;
|
|
2287
|
-
}
|
|
2288
|
-
};
|
|
2289
|
-
return fn;
|
|
2290
|
-
}
|
|
2291
|
-
function reverse2(fn) {
|
|
2292
|
-
return (a, b) => fn(a, b) * -1;
|
|
2293
|
-
}
|
|
2294
|
-
var ComparisonChain = class _ComparisonChain {
|
|
2295
|
-
constructor(_fns, _reversed = false) {
|
|
2296
|
-
this._fns = _fns;
|
|
2297
|
-
this._reversed = _reversed;
|
|
2298
|
-
}
|
|
2299
|
-
compare = (a, b) => {
|
|
2300
|
-
return this.doCompare(a, b) * (this._reversed ? -1 : 1);
|
|
2301
|
-
};
|
|
2302
|
-
sort = (arr) => {
|
|
2303
|
-
return [...arr].sort(this.compare);
|
|
2304
|
-
};
|
|
2305
|
-
then(getFn) {
|
|
2306
|
-
const cmp = getFn(createCompare());
|
|
2307
|
-
return this.thenBy(cmp);
|
|
2308
|
-
}
|
|
2309
|
-
thenBy(cmp) {
|
|
2310
|
-
return new _ComparisonChain([...this._fns, getComparisonFunction(cmp)]);
|
|
2311
|
-
}
|
|
2312
|
-
thenChain(transform, getFn) {
|
|
2313
|
-
const cmp = getFn(createCompare());
|
|
2314
|
-
return this.thenChainBy(transform, cmp);
|
|
2315
|
-
}
|
|
2316
|
-
thenChainBy(transform, cmp) {
|
|
2317
|
-
return new _ComparisonChain([...this._fns, applyTransformationBeforeComparison(transform, getComparisonFunction(cmp))]);
|
|
2318
|
-
}
|
|
2319
|
-
reversed() {
|
|
2320
|
-
return new _ComparisonChain([...this._fns], !this._reversed);
|
|
2321
|
-
}
|
|
2322
|
-
doCompare(a, b) {
|
|
2323
|
-
return this._fns.reduce((ret, fn) => {
|
|
2324
|
-
return ret !== 0 ? ret : fn(a, b);
|
|
2325
|
-
}, 0);
|
|
2326
|
-
}
|
|
2327
|
-
static create() {
|
|
2328
|
-
return {
|
|
2329
|
-
using: (getFn) => {
|
|
2330
|
-
return new _ComparisonChain([]).then(getFn);
|
|
2331
|
-
},
|
|
2332
|
-
usingTransformation: (transform, getFn) => {
|
|
2333
|
-
return new _ComparisonChain([]).thenChain(transform, getFn);
|
|
2334
|
-
}
|
|
2335
|
-
};
|
|
2336
|
-
}
|
|
2337
|
-
static createWith(getFn) {
|
|
2338
|
-
return this.create().using(getFn);
|
|
2339
|
-
}
|
|
2340
|
-
static createWithTransformation(transform, getFn) {
|
|
2341
|
-
return this.create().usingTransformation(transform, getFn);
|
|
2342
|
-
}
|
|
2343
|
-
};
|
|
2344
|
-
var ComparisonChain_default = ComparisonChain;
|
|
2345
|
-
function createCompare() {
|
|
2346
|
-
return {
|
|
2347
|
-
compareUsingGetter,
|
|
2348
|
-
compareUsingField,
|
|
2349
|
-
compareUsingStrings: compareStrings,
|
|
2350
|
-
compareUsingStringsIgnoringCase: (options) => compareStrings({ ...looseOptionsToStrict(options), ignoreCase: true }),
|
|
2351
|
-
compareUsingBooleans: compareBooleans,
|
|
2352
|
-
compareUsingNumbers: compareUsingNaturalOrder,
|
|
2353
|
-
compareUsingDates: compareUsingNaturalOrder,
|
|
2354
|
-
compareUsingFunction,
|
|
2355
|
-
placeFirst: (arr) => compareUsingSet(arr),
|
|
2356
|
-
placeFirstInOrder: (arr) => compareUsingArray(arr),
|
|
2357
|
-
placeLast: (arr) => reverse2(compareUsingSet(arr)),
|
|
2358
|
-
placeLastInOrder: (arr) => reverse2(compareUsingArray([...arr].reverse()))
|
|
2359
|
-
};
|
|
2360
|
-
}
|
|
2361
|
-
function applyTransformationBeforeComparison(transform, fn) {
|
|
2362
|
-
return (a, b) => fn(transform(a), transform(b));
|
|
2363
|
-
}
|
|
2364
|
-
function getComparisonFunction(arg) {
|
|
2365
|
-
return arg instanceof ComparisonChain ? arg.compare : arg;
|
|
2366
|
-
}
|
|
2367
|
-
|
|
2368
2123
|
// src/sorting/Sorter.ts
|
|
2369
2124
|
var defaultCompareValuesOptions = {
|
|
2370
2125
|
nullsFirst: false
|
|
@@ -2374,7 +2129,7 @@ var defaultCompareFunctionOptions = {
|
|
|
2374
2129
|
direction: "ASC"
|
|
2375
2130
|
};
|
|
2376
2131
|
var naturalOrderComparison = (a, b) => a < b ? -1 : 1;
|
|
2377
|
-
function
|
|
2132
|
+
function compareValues(a, b, cmp, { nullsFirst }) {
|
|
2378
2133
|
if (a === b)
|
|
2379
2134
|
return 0;
|
|
2380
2135
|
const nullA = isNullOrUndefined(a);
|
|
@@ -2385,16 +2140,16 @@ function compareValues2(a, b, cmp, { nullsFirst }) {
|
|
|
2385
2140
|
return nullA === nullsFirst ? -1 : 1;
|
|
2386
2141
|
return cmp(a, b);
|
|
2387
2142
|
}
|
|
2388
|
-
function
|
|
2389
|
-
return (a, b) =>
|
|
2143
|
+
function compareFunction(fn, cmp, { nullsFirst, direction }) {
|
|
2144
|
+
return (a, b) => applyDirection(compareValues(fn(a), fn(b), cmp, { nullsFirst }), direction);
|
|
2390
2145
|
}
|
|
2391
|
-
function
|
|
2146
|
+
function applyDirection(res, direction) {
|
|
2392
2147
|
return res * (direction === "ASC" ? 1 : -1);
|
|
2393
2148
|
}
|
|
2394
2149
|
function combine(f, g) {
|
|
2395
2150
|
return (t) => g(f(t));
|
|
2396
2151
|
}
|
|
2397
|
-
function
|
|
2152
|
+
function reverse2(fn) {
|
|
2398
2153
|
return (a, b) => fn(a, b) * -1;
|
|
2399
2154
|
}
|
|
2400
2155
|
var chain = (fns, cmpFn) => {
|
|
@@ -2404,34 +2159,34 @@ var transformAndChain = (fns, transform, cmpFn) => {
|
|
|
2404
2159
|
const fn = (a, b) => cmpFn(transform(a), transform(b));
|
|
2405
2160
|
return chain(fns, fn);
|
|
2406
2161
|
};
|
|
2407
|
-
var
|
|
2162
|
+
var compareStrings = (fns, transform, options = {}) => {
|
|
2408
2163
|
const { nullsFirst, direction, ignoreCase } = { ...defaultStringComparisonOptions, ...options };
|
|
2409
2164
|
if (ignoreCase)
|
|
2410
2165
|
transform = combine(transform, (t) => t.toLowerCase());
|
|
2411
|
-
return chain(fns,
|
|
2166
|
+
return chain(fns, compareFunction(transform, naturalOrderComparison, { nullsFirst, direction }));
|
|
2412
2167
|
};
|
|
2413
2168
|
var compareNumbers = (fns, transform, options = {}) => {
|
|
2414
2169
|
const { nullsFirst, direction } = { ...defaultNumberComparisonOptions, ...options };
|
|
2415
|
-
return chain(fns,
|
|
2170
|
+
return chain(fns, compareFunction(transform, naturalOrderComparison, { nullsFirst, direction }));
|
|
2416
2171
|
};
|
|
2417
2172
|
var compareDates = (fns, transform, options = {}) => {
|
|
2418
2173
|
const { nullsFirst, direction } = { ...defaultDateComparisonOptions, ...options };
|
|
2419
|
-
return chain(fns,
|
|
2174
|
+
return chain(fns, compareFunction(transform, naturalOrderComparison, { nullsFirst, direction }));
|
|
2420
2175
|
};
|
|
2421
2176
|
var compareTimeInstants = (fns, transform, options = {}) => {
|
|
2422
2177
|
const { nullsFirst, direction } = { ...defaultTimeInstantComparisonOptions, ...options };
|
|
2423
|
-
return chain(fns,
|
|
2178
|
+
return chain(fns, compareFunction(transform, (a, b) => a.isBefore(b) ? -1 : 1, { nullsFirst, direction }));
|
|
2424
2179
|
};
|
|
2425
2180
|
var compareTimeDurations = (fns, transform, options = {}) => {
|
|
2426
2181
|
const { nullsFirst, direction } = { ...defaultTimeDurationComparisonOptions, ...options };
|
|
2427
|
-
return chain(fns,
|
|
2182
|
+
return chain(fns, compareFunction(transform, (a, b) => a.isLessThan(b) ? -1 : 1, { nullsFirst, direction }));
|
|
2428
2183
|
};
|
|
2429
|
-
var
|
|
2184
|
+
var compareBooleans = (fns, transform, options) => {
|
|
2430
2185
|
const { nullsFirst, truesFirst } = { ...defaultBooleanComparisonOptions, ...options };
|
|
2431
|
-
return chain(fns,
|
|
2186
|
+
return chain(fns, compareFunction(transform, naturalOrderComparison, { nullsFirst, direction: truesFirst ? "DESC" : "ASC" }));
|
|
2432
2187
|
};
|
|
2433
2188
|
var prioritizeSet = (fns, transform, set, reversed = false) => {
|
|
2434
|
-
return
|
|
2189
|
+
return compareBooleans(fns, (t) => {
|
|
2435
2190
|
const r = transform(t);
|
|
2436
2191
|
return isDefined(r) && set.includes(r);
|
|
2437
2192
|
}, { truesFirst: !reversed, nullsFirst: false });
|
|
@@ -2495,25 +2250,25 @@ var next = (fns, transform) => {
|
|
|
2495
2250
|
const retForStrings = {
|
|
2496
2251
|
...retAsUsing,
|
|
2497
2252
|
inLexographicalOrder(opts = {}) {
|
|
2498
|
-
return
|
|
2253
|
+
return compareStrings(fns, transform, { direction: "ASC", ignoreCase: false, ...opts });
|
|
2499
2254
|
},
|
|
2500
2255
|
inLexographicalOrderIgnoringCase(opts = {}) {
|
|
2501
|
-
return
|
|
2256
|
+
return compareStrings(fns, transform, { direction: "ASC", ignoreCase: true, ...opts });
|
|
2502
2257
|
},
|
|
2503
2258
|
inReverseLexographicalOrder(opts = {}) {
|
|
2504
|
-
return
|
|
2259
|
+
return compareStrings(fns, transform, { direction: "DESC", ignoreCase: false, ...opts });
|
|
2505
2260
|
},
|
|
2506
2261
|
inReverseLexographicalOrderIgnoringCase(opts = {}) {
|
|
2507
|
-
return
|
|
2262
|
+
return compareStrings(fns, transform, { direction: "DESC", ignoreCase: true, ...opts });
|
|
2508
2263
|
}
|
|
2509
2264
|
};
|
|
2510
2265
|
const retForBooleans = {
|
|
2511
2266
|
...retAsUsing,
|
|
2512
2267
|
truesFirst(opts = {}) {
|
|
2513
|
-
return
|
|
2268
|
+
return compareBooleans(fns, transform, { truesFirst: true, ...opts });
|
|
2514
2269
|
},
|
|
2515
2270
|
falsesFirst(opts = {}) {
|
|
2516
|
-
return
|
|
2271
|
+
return compareBooleans(fns, transform, { truesFirst: false, ...opts });
|
|
2517
2272
|
}
|
|
2518
2273
|
};
|
|
2519
2274
|
const retForDates = {
|
|
@@ -2599,7 +2354,7 @@ function doCreateWithFunctions(fns) {
|
|
|
2599
2354
|
return next(fns, identity);
|
|
2600
2355
|
},
|
|
2601
2356
|
reversed() {
|
|
2602
|
-
return doCreateWithFunctions([...fns.map(
|
|
2357
|
+
return doCreateWithFunctions([...fns.map(reverse2)]);
|
|
2603
2358
|
},
|
|
2604
2359
|
compare: (a, b) => {
|
|
2605
2360
|
return compare(fns, a, b);
|
|
@@ -2635,12 +2390,11 @@ var Sorter = {
|
|
|
2635
2390
|
first: (arr, builder) => builder(doCreateEmpty()).first(arr),
|
|
2636
2391
|
last: (arr, builder) => builder(doCreateEmpty()).last(arr)
|
|
2637
2392
|
};
|
|
2638
|
-
var Sorting = Sorter;
|
|
2639
2393
|
|
|
2640
2394
|
// src/time/RandomTimeDuration.ts
|
|
2641
2395
|
function randomize(unit) {
|
|
2642
2396
|
return (a, b) => {
|
|
2643
|
-
return TimeDuration_default.fromMs(
|
|
2397
|
+
return TimeDuration_default.fromMs(randomNumberInInterval(unit.toMs(a), unit.toMs(b)));
|
|
2644
2398
|
};
|
|
2645
2399
|
}
|
|
2646
2400
|
var RandomTimeDuration = class {
|
|
@@ -2823,7 +2577,6 @@ function isUpgradable(obj) {
|
|
|
2823
2577
|
return isDefined(obj) && typeof obj === "object" && VERSION_FIELD in obj && isNumber(obj.$version) && isPositiveNumber(obj.$version);
|
|
2824
2578
|
}
|
|
2825
2579
|
export {
|
|
2826
|
-
ComparisonChain_default as ComparisonChain,
|
|
2827
2580
|
DataUpgrader,
|
|
2828
2581
|
Deferred,
|
|
2829
2582
|
DeferredCanceledError,
|
|
@@ -2839,7 +2592,6 @@ export {
|
|
|
2839
2592
|
RateThrottler,
|
|
2840
2593
|
Semaphore,
|
|
2841
2594
|
Sorter,
|
|
2842
|
-
Sorting,
|
|
2843
2595
|
StringParts,
|
|
2844
2596
|
TimeDuration,
|
|
2845
2597
|
TimeFrequency,
|
|
@@ -2939,7 +2691,6 @@ export {
|
|
|
2939
2691
|
multiplyBy,
|
|
2940
2692
|
noop,
|
|
2941
2693
|
not,
|
|
2942
|
-
omit,
|
|
2943
2694
|
omitFromJsonObject,
|
|
2944
2695
|
or,
|
|
2945
2696
|
pad,
|
|
@@ -2952,9 +2703,7 @@ export {
|
|
|
2952
2703
|
pluralize,
|
|
2953
2704
|
promiseSequence,
|
|
2954
2705
|
randomId,
|
|
2955
|
-
randomInterval,
|
|
2956
2706
|
randomNumberInInterval,
|
|
2957
|
-
randomPercentage,
|
|
2958
2707
|
range,
|
|
2959
2708
|
repeat,
|
|
2960
2709
|
reverse,
|
|
@@ -2980,7 +2729,6 @@ export {
|
|
|
2980
2729
|
upsert,
|
|
2981
2730
|
withTryCatch,
|
|
2982
2731
|
withTryCatchAsync,
|
|
2983
|
-
wrap,
|
|
2984
2732
|
wrapWithString,
|
|
2985
2733
|
xor
|
|
2986
2734
|
};
|