@zelgadis87/utils-core 5.0.2 → 5.0.4
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 +35 -14
- package/dist/time/TimeBase.d.ts +25 -14
- package/dist/time/TimeDuration.d.ts +4 -2
- package/dist/time/TimeInstant.d.ts +1 -1
- package/dist/time/TimeUnit.d.ts +1 -3
- package/dist/time/_index.d.ts +3 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/errors.d.ts +2 -2
- package/esbuild/index.cjs +120 -81
- package/esbuild/index.cjs.map +3 -3
- package/esbuild/index.mjs +108 -69
- package/esbuild/index.mjs.map +2 -2
- package/package.json +7 -7
- package/src/Optional.ts +88 -16
- package/src/time/RandomTimeDuration.ts +1 -1
- package/src/time/TimeBase.ts +32 -8
- package/src/time/TimeDuration.ts +11 -3
- package/src/time/TimeInstant.ts +1 -1
- package/src/time/TimeUnit.ts +1 -6
- package/src/time/_index.ts +3 -2
- package/src/utils/errors.ts +4 -4
package/esbuild/index.cjs
CHANGED
|
@@ -32,12 +32,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
|
|
33
33
|
// ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js
|
|
34
34
|
var require_format = __commonJS({
|
|
35
|
-
"../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js"(
|
|
35
|
+
"../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js"(exports2) {
|
|
36
36
|
"use strict";
|
|
37
|
-
Object.defineProperty(
|
|
37
|
+
Object.defineProperty(exports2, "__esModule", {
|
|
38
38
|
value: true
|
|
39
39
|
});
|
|
40
|
-
|
|
40
|
+
exports2["default"] = format2;
|
|
41
41
|
function ownKeys(object, enumerableOnly) {
|
|
42
42
|
var keys = Object.keys(object);
|
|
43
43
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -153,24 +153,24 @@ var require_format = __commonJS({
|
|
|
153
153
|
|
|
154
154
|
// ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js
|
|
155
155
|
var require_lib = __commonJS({
|
|
156
|
-
"../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js"(
|
|
156
|
+
"../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js"(exports2) {
|
|
157
157
|
"use strict";
|
|
158
|
-
Object.defineProperty(
|
|
158
|
+
Object.defineProperty(exports2, "__esModule", {
|
|
159
159
|
value: true
|
|
160
160
|
});
|
|
161
|
-
|
|
161
|
+
exports2.format = void 0;
|
|
162
162
|
var _format = require_format();
|
|
163
163
|
var _format2 = _interopRequireDefault(_format);
|
|
164
164
|
function _interopRequireDefault(obj) {
|
|
165
165
|
return obj && obj.__esModule ? obj : { "default": obj };
|
|
166
166
|
}
|
|
167
|
-
|
|
167
|
+
exports2.format = _format2["default"];
|
|
168
168
|
}
|
|
169
169
|
});
|
|
170
170
|
|
|
171
171
|
// src/index.ts
|
|
172
|
-
var
|
|
173
|
-
__export(
|
|
172
|
+
var index_exports = {};
|
|
173
|
+
__export(index_exports, {
|
|
174
174
|
DataUpgrader: () => DataUpgrader,
|
|
175
175
|
Deferred: () => Deferred,
|
|
176
176
|
DeferredCanceledError: () => DeferredCanceledError,
|
|
@@ -236,6 +236,8 @@ __export(src_exports, {
|
|
|
236
236
|
filterWithTypePredicate: () => filterWithTypePredicate,
|
|
237
237
|
first: () => first,
|
|
238
238
|
flatMapTruthys: () => flatMapTruthys,
|
|
239
|
+
getMessageFromError: () => getMessageFromError,
|
|
240
|
+
getStackFromError: () => getStackFromError,
|
|
239
241
|
groupByBoolean: () => groupByBoolean,
|
|
240
242
|
groupByBooleanWith: () => groupByBooleanWith,
|
|
241
243
|
groupByNumber: () => groupByNumber,
|
|
@@ -297,8 +299,6 @@ __export(src_exports, {
|
|
|
297
299
|
pipedInvoke: () => pipedInvoke,
|
|
298
300
|
pipedInvokeFromArray: () => pipedInvokeFromArray,
|
|
299
301
|
pluralize: () => pluralize,
|
|
300
|
-
printErrorMessage: () => printErrorMessage,
|
|
301
|
-
printErrorStack: () => printErrorStack,
|
|
302
302
|
promiseSequence: () => promiseSequence,
|
|
303
303
|
randomId: () => randomId,
|
|
304
304
|
randomNumberInInterval: () => randomNumberInInterval,
|
|
@@ -330,7 +330,7 @@ __export(src_exports, {
|
|
|
330
330
|
wrapWithString: () => wrapWithString,
|
|
331
331
|
xor: () => xor
|
|
332
332
|
});
|
|
333
|
-
module.exports = __toCommonJS(
|
|
333
|
+
module.exports = __toCommonJS(index_exports);
|
|
334
334
|
|
|
335
335
|
// src/async/Deferred.ts
|
|
336
336
|
var DeferredCanceledError = class extends Error {
|
|
@@ -433,8 +433,7 @@ var RateThrottler = class {
|
|
|
433
433
|
return slot.promise().then(() => fn());
|
|
434
434
|
} finally {
|
|
435
435
|
this._availableSlots.push(TimeInstant.now().addDuration(this.cooldown));
|
|
436
|
-
if (this._waitingRequests.length > 0)
|
|
437
|
-
this._waitingRequests.shift().resolve();
|
|
436
|
+
if (this._waitingRequests.length > 0) this._waitingRequests.shift().resolve();
|
|
438
437
|
}
|
|
439
438
|
};
|
|
440
439
|
if (this._availableSlots.length > 0) {
|
|
@@ -600,16 +599,14 @@ function sumBy(arr, getter) {
|
|
|
600
599
|
return sum(arr.map(getter));
|
|
601
600
|
}
|
|
602
601
|
function min(arr) {
|
|
603
|
-
if (arr.length === 0)
|
|
604
|
-
throw new Error("Cannot calculate value on empty array");
|
|
602
|
+
if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
|
|
605
603
|
return arr.reduce((min2, cur) => cur < min2 ? cur : min2);
|
|
606
604
|
}
|
|
607
605
|
function minBy(arr, getter) {
|
|
608
606
|
return min(arr.map(getter));
|
|
609
607
|
}
|
|
610
608
|
function max(arr) {
|
|
611
|
-
if (arr.length === 0)
|
|
612
|
-
throw new Error("Cannot calculate value on empty array");
|
|
609
|
+
if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
|
|
613
610
|
return arr.reduce((max2, cur) => cur > max2 ? cur : max2);
|
|
614
611
|
}
|
|
615
612
|
function maxBy(arr, getter) {
|
|
@@ -681,17 +678,13 @@ function not(predicate) {
|
|
|
681
678
|
return (t) => !predicate(t);
|
|
682
679
|
}
|
|
683
680
|
function and(...predicates) {
|
|
684
|
-
if (predicates.length === 0)
|
|
685
|
-
|
|
686
|
-
else if (predicates.length === 1)
|
|
687
|
-
return predicates[0];
|
|
681
|
+
if (predicates.length === 0) return constantTrue;
|
|
682
|
+
else if (predicates.length === 1) return predicates[0];
|
|
688
683
|
return (t) => predicates.reduce((prev, cur) => prev ? cur(t) : false, true);
|
|
689
684
|
}
|
|
690
685
|
function or(...predicates) {
|
|
691
|
-
if (predicates.length === 0)
|
|
692
|
-
|
|
693
|
-
else if (predicates.length === 1)
|
|
694
|
-
return predicates[0];
|
|
686
|
+
if (predicates.length === 0) return constantTrue;
|
|
687
|
+
else if (predicates.length === 1) return predicates[0];
|
|
695
688
|
return (t) => predicates.reduce((prev, cur) => prev ? true : cur(t), false);
|
|
696
689
|
}
|
|
697
690
|
function xor(a, b) {
|
|
@@ -735,13 +728,11 @@ function uniqByKey(arr, key) {
|
|
|
735
728
|
|
|
736
729
|
// src/utils/arrays.ts
|
|
737
730
|
function ensureArray(t) {
|
|
738
|
-
if (isNullOrUndefined(t))
|
|
739
|
-
return [];
|
|
731
|
+
if (isNullOrUndefined(t)) return [];
|
|
740
732
|
return t instanceof Array ? t : [t];
|
|
741
733
|
}
|
|
742
734
|
function ensureReadableArray(t) {
|
|
743
|
-
if (isNullOrUndefined(t))
|
|
744
|
-
return [];
|
|
735
|
+
if (isNullOrUndefined(t)) return [];
|
|
745
736
|
return t instanceof Array ? t : [t];
|
|
746
737
|
}
|
|
747
738
|
function isArray(t) {
|
|
@@ -760,8 +751,7 @@ function upsert(arr, item, isEqual) {
|
|
|
760
751
|
}
|
|
761
752
|
}
|
|
762
753
|
function range(start, end) {
|
|
763
|
-
if (end < start)
|
|
764
|
-
throw new Error();
|
|
754
|
+
if (end < start) throw new Error();
|
|
765
755
|
let length = end - start + 1;
|
|
766
756
|
return new Array(length).fill(1).map((_, i) => start + i);
|
|
767
757
|
}
|
|
@@ -820,8 +810,7 @@ function partition(arr, predicate) {
|
|
|
820
810
|
function mapFirstTruthy(arr, mapFn) {
|
|
821
811
|
for (let i = 0; i < arr.length; i++) {
|
|
822
812
|
const result = mapFn(arr[i]);
|
|
823
|
-
if (result)
|
|
824
|
-
return result;
|
|
813
|
+
if (result) return result;
|
|
825
814
|
}
|
|
826
815
|
return null;
|
|
827
816
|
}
|
|
@@ -849,8 +838,7 @@ function cssDeclarationRulesDictionaryToCss(syleDeclarationRulesForSelectorsProd
|
|
|
849
838
|
const syleDeclarationRulesForSelectors = produceableToValue(syleDeclarationRulesForSelectorsProduceable);
|
|
850
839
|
return Object.entries(syleDeclarationRulesForSelectors).map(([selector, styleDeclarationRules]) => {
|
|
851
840
|
const cssRules = cssSelectorDeclarationRulesDictionaryToCss(styleDeclarationRules, indent + 1);
|
|
852
|
-
if (!cssRules.length)
|
|
853
|
-
return null;
|
|
841
|
+
if (!cssRules.length) return null;
|
|
854
842
|
return repeat(tabulation, indent) + selector + space + openBracket + newLine + cssRules.join(newLine) + newLine + closeBracket;
|
|
855
843
|
}).filter(Boolean).join(newLine + newLine);
|
|
856
844
|
}
|
|
@@ -918,14 +906,14 @@ function asError(e) {
|
|
|
918
906
|
function isError(e) {
|
|
919
907
|
return e instanceof Error;
|
|
920
908
|
}
|
|
921
|
-
function
|
|
922
|
-
const maybeCause = error.cause ?
|
|
909
|
+
function getMessageFromError(error) {
|
|
910
|
+
const maybeCause = error.cause ? getMessageFromError(asError(error.cause)) : null;
|
|
923
911
|
const cause = maybeCause ? `
|
|
924
912
|
caused by: ${maybeCause}` : "";
|
|
925
913
|
return `${error.name}: ${error.message}${cause}`;
|
|
926
914
|
}
|
|
927
|
-
function
|
|
928
|
-
const maybeCause = error.cause ?
|
|
915
|
+
function getStackFromError(error) {
|
|
916
|
+
const maybeCause = error.cause ? getStackFromError(asError(error.cause)) : null;
|
|
929
917
|
const cause = maybeCause ? `
|
|
930
918
|
caused by: ${maybeCause}` : "";
|
|
931
919
|
const stack = error.stack && error.stack.includes(error.message) ? error.stack : error.message + " " + (error.stack ?? "");
|
|
@@ -937,8 +925,7 @@ function tryToParseJson(jsonContent) {
|
|
|
937
925
|
return withTryCatch(() => JSON.parse(jsonContent));
|
|
938
926
|
}
|
|
939
927
|
function jsonCloneDeep(a) {
|
|
940
|
-
if (null === a || "object" !== typeof a)
|
|
941
|
-
return a;
|
|
928
|
+
if (null === a || "object" !== typeof a) return a;
|
|
942
929
|
if (a instanceof Date) {
|
|
943
930
|
return new Date(a.getTime());
|
|
944
931
|
} else if (a instanceof Array) {
|
|
@@ -1045,13 +1032,10 @@ function clampInt0_100(n) {
|
|
|
1045
1032
|
function tryToParseNumber(numberStr) {
|
|
1046
1033
|
return withTryCatch(() => {
|
|
1047
1034
|
const type = typeof ensureDefined(numberStr);
|
|
1048
|
-
if (type !== "string")
|
|
1049
|
-
|
|
1050
|
-
if (numberStr.trim().length === 0)
|
|
1051
|
-
throw new Error("Invalid number given: " + numberStr);
|
|
1035
|
+
if (type !== "string") throw new Error("Invalid number given: " + numberStr);
|
|
1036
|
+
if (numberStr.trim().length === 0) throw new Error("Invalid number given: " + numberStr);
|
|
1052
1037
|
const num = Number(numberStr);
|
|
1053
|
-
if (isNaN(num))
|
|
1054
|
-
throw new Error("Invalid number given: " + numberStr);
|
|
1038
|
+
if (isNaN(num)) throw new Error("Invalid number given: " + numberStr);
|
|
1055
1039
|
return num;
|
|
1056
1040
|
});
|
|
1057
1041
|
}
|
|
@@ -1131,8 +1115,7 @@ var StringParts = class _StringParts {
|
|
|
1131
1115
|
return new _StringParts(...this.parts.map((part) => part.toLowerCase()));
|
|
1132
1116
|
}
|
|
1133
1117
|
capitalizeFirst() {
|
|
1134
|
-
if (!this.length)
|
|
1135
|
-
return this;
|
|
1118
|
+
if (!this.length) return this;
|
|
1136
1119
|
return new _StringParts(capitalizeWord(this.first), ...this.tail.map((part) => part.toLowerCase()));
|
|
1137
1120
|
}
|
|
1138
1121
|
capitalizeEach() {
|
|
@@ -1161,8 +1144,7 @@ var StringParts = class _StringParts {
|
|
|
1161
1144
|
return this.toLowerCase().join("_");
|
|
1162
1145
|
}
|
|
1163
1146
|
toCamelCase() {
|
|
1164
|
-
if (!this.length)
|
|
1165
|
-
return "";
|
|
1147
|
+
if (!this.length) return "";
|
|
1166
1148
|
return [this.first.toLowerCase(), ...this.tail.map(capitalizeWord)].join("");
|
|
1167
1149
|
}
|
|
1168
1150
|
toKebabCase() {
|
|
@@ -1236,8 +1218,7 @@ function stringToNumber(s) {
|
|
|
1236
1218
|
}
|
|
1237
1219
|
function pad(str, n, char, where = "left") {
|
|
1238
1220
|
const length = ensureDefined(str).length;
|
|
1239
|
-
if (length >= ensureDefined(n))
|
|
1240
|
-
return str;
|
|
1221
|
+
if (length >= ensureDefined(n)) return str;
|
|
1241
1222
|
if (ensureDefined(char).length !== 1)
|
|
1242
1223
|
throw new Error("Illegal pad character");
|
|
1243
1224
|
const padding = repeat(char, n - length);
|
|
@@ -1467,15 +1448,11 @@ var TimeUnit = class _TimeUnit {
|
|
|
1467
1448
|
toDays(value) {
|
|
1468
1449
|
return this.toUnit(value, _TimeUnit.DAYS);
|
|
1469
1450
|
}
|
|
1470
|
-
toWeeks(value) {
|
|
1471
|
-
return this.toUnit(value, _TimeUnit.WEEKS);
|
|
1472
|
-
}
|
|
1473
1451
|
static MILLISECONDS = new _TimeUnit(1);
|
|
1474
1452
|
static SECONDS = new _TimeUnit(1e3 * _TimeUnit.MILLISECONDS.multiplier);
|
|
1475
1453
|
static MINUTES = new _TimeUnit(60 * _TimeUnit.SECONDS.multiplier);
|
|
1476
1454
|
static HOURS = new _TimeUnit(60 * _TimeUnit.MINUTES.multiplier);
|
|
1477
1455
|
static DAYS = new _TimeUnit(24 * _TimeUnit.HOURS.multiplier);
|
|
1478
|
-
static WEEKS = new _TimeUnit(7 * _TimeUnit.DAYS.multiplier);
|
|
1479
1456
|
};
|
|
1480
1457
|
|
|
1481
1458
|
// src/time/TimeBase.ts
|
|
@@ -1484,18 +1461,33 @@ var TimeBase = class {
|
|
|
1484
1461
|
constructor(value, unit) {
|
|
1485
1462
|
this._ms = unit.toMs(value);
|
|
1486
1463
|
}
|
|
1464
|
+
/**
|
|
1465
|
+
* Total number of milliseconds, rounded down.
|
|
1466
|
+
*/
|
|
1487
1467
|
get ms() {
|
|
1488
1468
|
return Math.floor(this._ms / TimeUnit.MILLISECONDS.multiplier);
|
|
1489
1469
|
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Total number of seconds, rounded down.
|
|
1472
|
+
*/
|
|
1490
1473
|
get seconds() {
|
|
1491
1474
|
return Math.floor(this._ms / TimeUnit.SECONDS.multiplier);
|
|
1492
1475
|
}
|
|
1476
|
+
/**
|
|
1477
|
+
* Total number of minutes, rounded down.
|
|
1478
|
+
*/
|
|
1493
1479
|
get minutes() {
|
|
1494
1480
|
return Math.floor(this._ms / TimeUnit.MINUTES.multiplier);
|
|
1495
1481
|
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Total number of hours, rounded down.
|
|
1484
|
+
*/
|
|
1496
1485
|
get hours() {
|
|
1497
1486
|
return Math.floor(this._ms / TimeUnit.HOURS.multiplier);
|
|
1498
1487
|
}
|
|
1488
|
+
/**
|
|
1489
|
+
* Total number of days, rounded down.
|
|
1490
|
+
*/
|
|
1499
1491
|
get days() {
|
|
1500
1492
|
return Math.floor(this._ms / TimeUnit.DAYS.multiplier);
|
|
1501
1493
|
}
|
|
@@ -1540,17 +1532,18 @@ var TimeBase = class {
|
|
|
1540
1532
|
}
|
|
1541
1533
|
toUnits() {
|
|
1542
1534
|
return {
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
minutes: Math.floor(this.
|
|
1546
|
-
|
|
1535
|
+
milliseconds: this.ms % TimeUnit.SECONDS.multiplier,
|
|
1536
|
+
seconds: Math.floor(this.seconds % 60),
|
|
1537
|
+
minutes: Math.floor(this.minutes % 60),
|
|
1538
|
+
hours: Math.floor(this.hours % 24),
|
|
1539
|
+
days: Math.floor(this.days)
|
|
1547
1540
|
};
|
|
1548
1541
|
}
|
|
1549
|
-
static
|
|
1542
|
+
static unitsToMs(units) {
|
|
1550
1543
|
if (!units)
|
|
1551
1544
|
throw new Error("Invalid units given");
|
|
1552
1545
|
let ms = 0;
|
|
1553
|
-
ms += units.
|
|
1546
|
+
ms += (units.milliseconds ?? 0) * TimeUnit.MILLISECONDS.multiplier;
|
|
1554
1547
|
ms += (units.seconds ?? 0) * TimeUnit.SECONDS.multiplier;
|
|
1555
1548
|
ms += (units.minutes ?? 0) * TimeUnit.MINUTES.multiplier;
|
|
1556
1549
|
ms += (units.hours ?? 0) * TimeUnit.HOURS.multiplier;
|
|
@@ -1600,8 +1593,7 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1600
1593
|
get formatted() {
|
|
1601
1594
|
const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
|
|
1602
1595
|
const units = this.toUnits();
|
|
1603
|
-
if (units.days >= 1)
|
|
1604
|
-
return format2(units.days, "d", units.hours, "h");
|
|
1596
|
+
if (units.days >= 1) return format2(units.days, "d", units.hours, "h");
|
|
1605
1597
|
else if (units.hours >= 1)
|
|
1606
1598
|
return format2(units.hours, "h", units.minutes, "m");
|
|
1607
1599
|
else if (units.minutes >= 1)
|
|
@@ -1712,6 +1704,9 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1712
1704
|
isNotEmpty() {
|
|
1713
1705
|
return this.ms > 0;
|
|
1714
1706
|
}
|
|
1707
|
+
toUnits() {
|
|
1708
|
+
return super.toUnits();
|
|
1709
|
+
}
|
|
1715
1710
|
/**
|
|
1716
1711
|
* This method is used to provide a better DX when inspecting a TimeInstant object in DevTools.
|
|
1717
1712
|
*/
|
|
@@ -1725,7 +1720,7 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1725
1720
|
const match = humanTime.trim().match(/^(?:([0-9]+)d|)\s*(?:([0-9]+)h|)\s*(?:([0-9]+)m|)\s*(?:([0-9]+)s|)$/);
|
|
1726
1721
|
if (match) {
|
|
1727
1722
|
const [_, days, hours, minutes, seconds] = match;
|
|
1728
|
-
return new _TimeDuration(TimeBase.
|
|
1723
|
+
return new _TimeDuration(TimeBase.unitsToMs({ days: Number(days ?? 0), hours: Number(hours ?? 0), minutes: Number(minutes ?? 0), seconds: Number(seconds ?? 0) }), TimeUnit.MILLISECONDS);
|
|
1729
1724
|
}
|
|
1730
1725
|
throw new Error("Failed to parse time: " + humanTime);
|
|
1731
1726
|
}
|
|
@@ -1777,6 +1772,9 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1777
1772
|
static fromJSON(ms) {
|
|
1778
1773
|
return _TimeDuration.ms(ms);
|
|
1779
1774
|
}
|
|
1775
|
+
static fromUnits(parameters) {
|
|
1776
|
+
return _TimeDuration.ms(TimeBase.unitsToMs(parameters));
|
|
1777
|
+
}
|
|
1780
1778
|
};
|
|
1781
1779
|
function isAllowedTimeDuration(t) {
|
|
1782
1780
|
return typeof t === "number" && t > 0 || t instanceof TimeDuration;
|
|
@@ -1854,8 +1852,7 @@ var getFromDate = {
|
|
|
1854
1852
|
};
|
|
1855
1853
|
var toReferenceDate = (x) => {
|
|
1856
1854
|
ensureDefined(x);
|
|
1857
|
-
if (isTimeInstant(x))
|
|
1858
|
-
return x.toDate();
|
|
1855
|
+
if (isTimeInstant(x)) return x.toDate();
|
|
1859
1856
|
return x;
|
|
1860
1857
|
};
|
|
1861
1858
|
function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInstant.now()) {
|
|
@@ -2250,6 +2247,12 @@ var Optional = class _Optional {
|
|
|
2250
2247
|
this._value = t;
|
|
2251
2248
|
this._present = true;
|
|
2252
2249
|
}
|
|
2250
|
+
setNullable(t) {
|
|
2251
|
+
if (isDefined(t)) {
|
|
2252
|
+
return this.set(t);
|
|
2253
|
+
}
|
|
2254
|
+
return this;
|
|
2255
|
+
}
|
|
2253
2256
|
clear() {
|
|
2254
2257
|
this._value = void 0;
|
|
2255
2258
|
this._present = false;
|
|
@@ -2275,32 +2278,69 @@ var Optional = class _Optional {
|
|
|
2275
2278
|
callbackIfPresent(this.get());
|
|
2276
2279
|
}
|
|
2277
2280
|
}
|
|
2278
|
-
|
|
2281
|
+
orElseReturn(newValue) {
|
|
2279
2282
|
if (this.isPresent()) {
|
|
2280
|
-
return this.
|
|
2283
|
+
return this.get();
|
|
2281
2284
|
} else {
|
|
2282
2285
|
return newValue;
|
|
2283
2286
|
}
|
|
2284
2287
|
}
|
|
2285
|
-
|
|
2288
|
+
orElse = this.orElseReturn.bind(this);
|
|
2289
|
+
orElseProduce(newValueProducer) {
|
|
2286
2290
|
if (this.isPresent()) {
|
|
2287
|
-
return this.
|
|
2291
|
+
return this.get();
|
|
2288
2292
|
} else {
|
|
2289
2293
|
return newValueProducer();
|
|
2290
2294
|
}
|
|
2291
2295
|
}
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2296
|
+
orElseGet = this.orElseProduce.bind(this);
|
|
2297
|
+
orElseReturnAndApply(newValue) {
|
|
2298
|
+
if (this.isPresent()) {
|
|
2299
|
+
return this.get();
|
|
2300
|
+
} else {
|
|
2301
|
+
this.set(newValue);
|
|
2302
|
+
return newValue;
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
orElseProduceAndApply(newValueProducer) {
|
|
2306
|
+
if (this.isPresent()) {
|
|
2307
|
+
return this.get();
|
|
2308
|
+
} else {
|
|
2309
|
+
const newValue = newValueProducer();
|
|
2310
|
+
this.set(newValue);
|
|
2311
|
+
return newValue;
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
orElseReturnNullableAndApply(newValue) {
|
|
2315
|
+
if (this.isPresent()) {
|
|
2316
|
+
return this;
|
|
2317
|
+
} else {
|
|
2318
|
+
this.setNullable(newValue);
|
|
2319
|
+
return this;
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
orElseProduceNullableAndApply(newValueProducer) {
|
|
2323
|
+
if (this.isPresent()) {
|
|
2324
|
+
return this;
|
|
2325
|
+
} else {
|
|
2326
|
+
const newValue = newValueProducer();
|
|
2327
|
+
this.setNullable(newValue);
|
|
2328
|
+
return this;
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
orElseReturnNullable(newValue) {
|
|
2332
|
+
if (this.isEmpty()) return _Optional.ofNullable(newValue);
|
|
2295
2333
|
return this;
|
|
2296
2334
|
}
|
|
2297
|
-
|
|
2335
|
+
orElseNullable = this.orElseReturnNullable.bind(this);
|
|
2336
|
+
orElseProduceNullable(newValueProducer) {
|
|
2298
2337
|
if (this.isEmpty()) {
|
|
2299
2338
|
const newValue = newValueProducer();
|
|
2300
2339
|
return _Optional.ofNullable(newValue);
|
|
2301
2340
|
}
|
|
2302
2341
|
return this;
|
|
2303
2342
|
}
|
|
2343
|
+
orElseGetNullable = this.orElseProduceNullable.bind(this);
|
|
2304
2344
|
orElseThrow(errorProducer) {
|
|
2305
2345
|
if (this.isEmpty())
|
|
2306
2346
|
throw errorProducer();
|
|
@@ -2421,8 +2461,7 @@ var prioritizeSet = (fns, transform, set, reversed = false) => {
|
|
|
2421
2461
|
var prioritizeArray = (fns, transform, arr, reversed = false) => {
|
|
2422
2462
|
return compareNumbers(fns, (t) => {
|
|
2423
2463
|
const r = transform(t);
|
|
2424
|
-
if (!isDefined(r))
|
|
2425
|
-
return Number.MAX_VALUE;
|
|
2464
|
+
if (!isDefined(r)) return Number.MAX_VALUE;
|
|
2426
2465
|
const indexOf = arr.indexOf(r);
|
|
2427
2466
|
return indexOf === -1 ? Number.MAX_VALUE : indexOf;
|
|
2428
2467
|
}, { direction: reversed ? "DESC" : "ASC", nullsFirst: false });
|
|
@@ -2870,6 +2909,8 @@ function isUpgradable(obj) {
|
|
|
2870
2909
|
filterWithTypePredicate,
|
|
2871
2910
|
first,
|
|
2872
2911
|
flatMapTruthys,
|
|
2912
|
+
getMessageFromError,
|
|
2913
|
+
getStackFromError,
|
|
2873
2914
|
groupByBoolean,
|
|
2874
2915
|
groupByBooleanWith,
|
|
2875
2916
|
groupByNumber,
|
|
@@ -2931,8 +2972,6 @@ function isUpgradable(obj) {
|
|
|
2931
2972
|
pipedInvoke,
|
|
2932
2973
|
pipedInvokeFromArray,
|
|
2933
2974
|
pluralize,
|
|
2934
|
-
printErrorMessage,
|
|
2935
|
-
printErrorStack,
|
|
2936
2975
|
promiseSequence,
|
|
2937
2976
|
randomId,
|
|
2938
2977
|
randomNumberInInterval,
|