@ls-stack/utils 1.13.1 → 2.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/arrayUtils.cjs +91 -0
- package/dist/arrayUtils.d.cts +51 -0
- package/dist/arrayUtils.js +1 -2
- package/dist/assertions.cjs +99 -0
- package/dist/assertions.d.cts +17 -0
- package/dist/assertions.js +1 -2
- package/dist/castValues.cjs +41 -0
- package/dist/castValues.d.cts +4 -0
- package/dist/castValues.js +0 -1
- package/dist/{chunk-FYMTZQ42.js → chunk-4UGSP3L3.js} +0 -1
- package/dist/{chunk-HLFWWIDK.js → chunk-5DZT3Z5Z.js} +0 -1
- package/dist/{chunk-W7X6NSGR.js → chunk-AZBBTE33.js} +0 -1
- package/dist/{chunk-MMKMF4GG.js → chunk-IATIXMCE.js} +0 -1
- package/dist/chunk-JOBPQAI3.js +147 -0
- package/dist/{chunk-M74KKYE4.js → chunk-KCOXGSRA.js} +0 -1
- package/dist/{chunk-NKCC3375.js → chunk-NWXBMMHO.js} +0 -1
- package/dist/{chunk-SNAAKCTH.js → chunk-RVVH3MDA.js} +0 -1
- package/dist/{chunk-4QK76IRX.js → chunk-T5WDDPFI.js} +1 -6
- package/dist/{chunk-GLZ5MZC5.js → chunk-V2L472LS.js} +0 -30
- package/dist/consoleFmt.cjs +84 -0
- package/dist/consoleFmt.d.cts +48 -0
- package/dist/consoleFmt.js +0 -1
- package/dist/conversions.cjs +44 -0
- package/dist/conversions.d.cts +3 -0
- package/dist/conversions.js +1 -2
- package/dist/createThrottleController.cjs +183 -0
- package/dist/createThrottleController.d.cts +16 -0
- package/dist/createThrottleController.js +2 -3
- package/dist/debounce.cjs +125 -0
- package/dist/debounce.d.cts +45 -0
- package/dist/debounce.js +0 -1
- package/dist/dedent.cjs +57 -0
- package/dist/dedent.d.cts +4 -0
- package/dist/dedent.js +0 -1
- package/dist/deepEqual.cjs +88 -0
- package/dist/deepEqual.d.cts +4 -0
- package/dist/deepEqual.js +1 -2
- package/dist/enhancedMap.cjs +128 -0
- package/dist/enhancedMap.d.cts +20 -0
- package/dist/enhancedMap.d.ts +0 -2
- package/dist/enhancedMap.js +2 -3
- package/dist/exhaustiveMatch.cjs +55 -0
- package/dist/exhaustiveMatch.d.cts +6 -0
- package/dist/exhaustiveMatch.js +0 -1
- package/dist/interpolate.cjs +88 -0
- package/dist/interpolate.d.cts +11 -0
- package/dist/interpolate.js +2 -3
- package/dist/levenshtein.cjs +180 -0
- package/dist/levenshtein.d.cts +5 -0
- package/dist/levenshtein.js +0 -1
- package/dist/main.cjs +4 -0
- package/dist/main.d.cts +2 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.js +0 -1
- package/dist/mathUtils.cjs +50 -0
- package/dist/mathUtils.d.cts +6 -0
- package/dist/mathUtils.js +1 -2
- package/dist/objUtils.cjs +67 -0
- package/dist/objUtils.d.cts +7 -0
- package/dist/objUtils.js +1 -2
- package/dist/parallelAsyncCalls.cjs +265 -0
- package/dist/{parallelAsyncResultCalls.d.ts → parallelAsyncCalls.d.cts} +7 -7
- package/dist/parallelAsyncCalls.d.ts +76 -0
- package/dist/{parallelAsyncResultCalls.js → parallelAsyncCalls.js} +7 -9
- package/dist/promiseUtils.cjs +38 -0
- package/dist/promiseUtils.d.cts +8 -0
- package/dist/promiseUtils.js +0 -1
- package/dist/rsResult.cjs +179 -0
- package/dist/rsResult.d.cts +88 -0
- package/dist/rsResult.d.ts +33 -63
- package/dist/rsResult.js +6 -10
- package/dist/runShellCmd.cjs +127 -0
- package/dist/runShellCmd.d.cts +23 -0
- package/dist/runShellCmd.d.ts +2 -1
- package/dist/runShellCmd.js +9 -4
- package/dist/shallowEqual.cjs +88 -0
- package/dist/shallowEqual.d.cts +4 -0
- package/dist/shallowEqual.js +0 -1
- package/dist/sleep.cjs +32 -0
- package/dist/sleep.d.cts +3 -0
- package/dist/sleep.js +1 -2
- package/dist/stringUtils.cjs +66 -0
- package/dist/stringUtils.d.cts +16 -0
- package/dist/stringUtils.d.ts +1 -3
- package/dist/stringUtils.js +1 -4
- package/dist/testUtils.cjs +357 -0
- package/dist/testUtils.d.cts +38 -0
- package/dist/testUtils.js +17 -9
- package/dist/typingFnUtils.cjs +55 -0
- package/dist/typingFnUtils.d.cts +15 -0
- package/dist/typingFnUtils.js +0 -1
- package/dist/typingTestUtils.cjs +43 -0
- package/dist/typingTestUtils.d.cts +12 -0
- package/dist/typingTestUtils.js +0 -1
- package/dist/typingUtils.cjs +18 -0
- package/dist/typingUtils.d.cts +11 -0
- package/dist/typingUtils.js +0 -1
- package/dist/yamlStringify.cjs +346 -0
- package/dist/yamlStringify.d.cts +8 -0
- package/dist/yamlStringify.js +3 -4
- package/package.json +64 -34
- package/dist/arrayUtils.js.map +0 -1
- package/dist/assertions.js.map +0 -1
- package/dist/castValues.js.map +0 -1
- package/dist/chunk-4QK76IRX.js.map +0 -1
- package/dist/chunk-FYMTZQ42.js.map +0 -1
- package/dist/chunk-GLZ5MZC5.js.map +0 -1
- package/dist/chunk-HLFWWIDK.js.map +0 -1
- package/dist/chunk-I7ZDKDUM.js +0 -217
- package/dist/chunk-I7ZDKDUM.js.map +0 -1
- package/dist/chunk-M74KKYE4.js.map +0 -1
- package/dist/chunk-MMKMF4GG.js.map +0 -1
- package/dist/chunk-NKCC3375.js.map +0 -1
- package/dist/chunk-SNAAKCTH.js.map +0 -1
- package/dist/chunk-W7X6NSGR.js.map +0 -1
- package/dist/consoleFmt.js.map +0 -1
- package/dist/conversions.js.map +0 -1
- package/dist/createThrottleController.js.map +0 -1
- package/dist/debounce.js.map +0 -1
- package/dist/dedent.js.map +0 -1
- package/dist/deepEqual.js.map +0 -1
- package/dist/enhancedMap.js.map +0 -1
- package/dist/exhaustiveMatch.js.map +0 -1
- package/dist/interpolate.js.map +0 -1
- package/dist/levenshtein.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/dist/mathUtils.js.map +0 -1
- package/dist/objUtils.js.map +0 -1
- package/dist/parallelAsyncResultCalls.js.map +0 -1
- package/dist/promiseUtils.js.map +0 -1
- package/dist/rsResult.js.map +0 -1
- package/dist/runShellCmd.js.map +0 -1
- package/dist/shallowEqual.js.map +0 -1
- package/dist/sleep.js.map +0 -1
- package/dist/stringUtils.js.map +0 -1
- package/dist/testUtils.js.map +0 -1
- package/dist/typingFnUtils.js.map +0 -1
- package/dist/typingTestUtils.js.map +0 -1
- package/dist/typingUtils.js.map +0 -1
- package/dist/yamlStringify.js.map +0 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/arrayUtils.ts
|
|
21
|
+
var arrayUtils_exports = {};
|
|
22
|
+
__export(arrayUtils_exports, {
|
|
23
|
+
arrayWithPrev: () => arrayWithPrev,
|
|
24
|
+
arrayWithPrevAndIndex: () => arrayWithPrevAndIndex,
|
|
25
|
+
filterAndMap: () => filterAndMap,
|
|
26
|
+
isInArray: () => isInArray,
|
|
27
|
+
sortBy: () => sortBy
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(arrayUtils_exports);
|
|
30
|
+
function filterAndMap(array, mapFilter) {
|
|
31
|
+
const result = [];
|
|
32
|
+
let i = -1;
|
|
33
|
+
for (const item of array) {
|
|
34
|
+
i += 1;
|
|
35
|
+
const filterResult = mapFilter(item, i);
|
|
36
|
+
if (filterResult !== false) {
|
|
37
|
+
result.push(filterResult);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
function sortBy(arr, sortByValue, props = "asc") {
|
|
43
|
+
const order = Array.isArray(props) || typeof props === "string" ? props : props.order ?? "asc";
|
|
44
|
+
return [...arr].sort((a, b) => {
|
|
45
|
+
const _aPriority = sortByValue(a);
|
|
46
|
+
const _bPriority = sortByValue(b);
|
|
47
|
+
const aPriority = Array.isArray(_aPriority) ? _aPriority : [_aPriority];
|
|
48
|
+
const bPriority = Array.isArray(_bPriority) ? _bPriority : [_bPriority];
|
|
49
|
+
for (let i = 0; i < aPriority.length; i++) {
|
|
50
|
+
const levelOrder = typeof order === "string" ? order : order[i] ?? "asc";
|
|
51
|
+
const aP = aPriority[i] ?? 0;
|
|
52
|
+
const bP = bPriority[i] ?? 0;
|
|
53
|
+
if (aP === bP) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (bP === Infinity || aP === -Infinity || aP < bP) {
|
|
57
|
+
return levelOrder === "asc" ? -1 : 1;
|
|
58
|
+
}
|
|
59
|
+
if (aP === Infinity || bP === -Infinity || aP > bP) {
|
|
60
|
+
return levelOrder === "asc" ? 1 : -1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return 0;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function arrayWithPrev(array) {
|
|
67
|
+
return array.map((item, i) => [item, array[i - 1] ?? null]);
|
|
68
|
+
}
|
|
69
|
+
function arrayWithPrevAndIndex(array) {
|
|
70
|
+
return array.map((item, i) => ({
|
|
71
|
+
item,
|
|
72
|
+
prev: array[i - 1] ?? null,
|
|
73
|
+
index: i
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
function isInArray(value, oneOf) {
|
|
77
|
+
for (let i = 0; i < oneOf.length; i++) {
|
|
78
|
+
if (oneOf[i] === value) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
arrayWithPrev,
|
|
87
|
+
arrayWithPrevAndIndex,
|
|
88
|
+
filterAndMap,
|
|
89
|
+
isInArray,
|
|
90
|
+
sortBy
|
|
91
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* allow to filter and map with better typing ergonomics
|
|
3
|
+
*
|
|
4
|
+
* In the `mapFilter` function return `false` to reject the item, or any other
|
|
5
|
+
* value to map it.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Filter reject and turn value into `value mapped`
|
|
9
|
+
* const items = ['value', 'value', 'reject', 'reject'];
|
|
10
|
+
*
|
|
11
|
+
* const mappedItems = filterAndMap(items, (item) =>
|
|
12
|
+
* item === 'reject'
|
|
13
|
+
* ? false
|
|
14
|
+
* : `${item} mapped`,
|
|
15
|
+
* );
|
|
16
|
+
*
|
|
17
|
+
* mappedItems; // ['value mapped', 'value mapped']
|
|
18
|
+
*/
|
|
19
|
+
declare function filterAndMap<T, R>(array: IterableIterator<T> | readonly T[], mapFilter: (item: T, index: number) => false | R): R[];
|
|
20
|
+
type FilterAndMapReturn<T> = false | T;
|
|
21
|
+
type SortOrder = 'desc' | 'asc';
|
|
22
|
+
/**
|
|
23
|
+
* Sort an array based on a value
|
|
24
|
+
*
|
|
25
|
+
* Sort by `ascending` order by default
|
|
26
|
+
*
|
|
27
|
+
* Use `Infinity` as as wildcard to absolute max and min values
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const items = [1, 3, 2, 4];
|
|
31
|
+
*
|
|
32
|
+
* const sortedItems = sortBy(items, (item) => item);
|
|
33
|
+
* // [1, 2, 3, 4]
|
|
34
|
+
*
|
|
35
|
+
* const items2 = [{ a: 1, b: 2 }, { a: 2, b: 1 }, { a: 1, b: 1}]
|
|
36
|
+
*
|
|
37
|
+
* // return a array to sort by multiple values
|
|
38
|
+
* const sortedItems = sortBy(items, (item) => [item.a, item.b]);
|
|
39
|
+
**/
|
|
40
|
+
declare function sortBy<T>(arr: T[], sortByValue: (item: T) => (number | string)[] | number | string, props?: {
|
|
41
|
+
order?: SortOrder | SortOrder[];
|
|
42
|
+
} | SortOrder | SortOrder[]): T[];
|
|
43
|
+
declare function arrayWithPrev<T>(array: T[]): [current: T, prev: T | null][];
|
|
44
|
+
declare function arrayWithPrevAndIndex<T>(array: T[]): {
|
|
45
|
+
item: T;
|
|
46
|
+
prev: T | null;
|
|
47
|
+
index: number;
|
|
48
|
+
}[];
|
|
49
|
+
declare function isInArray<T, const U extends T>(value: T, oneOf: readonly U[]): value is U;
|
|
50
|
+
|
|
51
|
+
export { type FilterAndMapReturn, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, isInArray, sortBy };
|
package/dist/arrayUtils.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
filterAndMap,
|
|
5
5
|
isInArray,
|
|
6
6
|
sortBy
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-AZBBTE33.js";
|
|
8
8
|
export {
|
|
9
9
|
arrayWithPrev,
|
|
10
10
|
arrayWithPrevAndIndex,
|
|
@@ -12,4 +12,3 @@ export {
|
|
|
12
12
|
isInArray,
|
|
13
13
|
sortBy
|
|
14
14
|
};
|
|
15
|
-
//# sourceMappingURL=arrayUtils.js.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/assertions.ts
|
|
21
|
+
var assertions_exports = {};
|
|
22
|
+
__export(assertions_exports, {
|
|
23
|
+
assertIsNotNullish: () => assertIsNotNullish,
|
|
24
|
+
assertIsNotUndefined: () => assertIsNotUndefined,
|
|
25
|
+
exhaustiveCheck: () => exhaustiveCheck,
|
|
26
|
+
invariant: () => invariant,
|
|
27
|
+
isFunction: () => isFunction,
|
|
28
|
+
isObject: () => isObject,
|
|
29
|
+
isPlainObject: () => isPlainObject,
|
|
30
|
+
isPromise: () => isPromise,
|
|
31
|
+
notNullish: () => notNullish,
|
|
32
|
+
notUndefined: () => notUndefined
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(assertions_exports);
|
|
35
|
+
var undefErrMsg = "not undefined assertion failed";
|
|
36
|
+
var nullishErrMsg = "not nullish assertion failed";
|
|
37
|
+
function notUndefined(value) {
|
|
38
|
+
if (value === void 0) {
|
|
39
|
+
throw new Error(undefErrMsg);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function notNullish(value) {
|
|
44
|
+
if (value === void 0 || value === null) {
|
|
45
|
+
throw new Error(nullishErrMsg);
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
function assertIsNotNullish(value, errorMsg = nullishErrMsg) {
|
|
50
|
+
if (value === void 0 || value === null) {
|
|
51
|
+
throw new Error(errorMsg);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function assertIsNotUndefined(value, errorMsg = undefErrMsg) {
|
|
55
|
+
if (value === void 0) {
|
|
56
|
+
throw new Error(errorMsg);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function invariant(condition, errorMsg = "Invariant violation") {
|
|
60
|
+
if (!condition) {
|
|
61
|
+
throw new Error(`Invariant violation: ${errorMsg}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function exhaustiveCheck(narrowedType) {
|
|
65
|
+
return new Error("This should never happen");
|
|
66
|
+
}
|
|
67
|
+
function isObject(value) {
|
|
68
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
69
|
+
}
|
|
70
|
+
function isFunction(value) {
|
|
71
|
+
return typeof value === "function";
|
|
72
|
+
}
|
|
73
|
+
function isPromise(value) {
|
|
74
|
+
return isObject(value) && "then" in value;
|
|
75
|
+
}
|
|
76
|
+
function isPlainObject(value) {
|
|
77
|
+
if (!value || typeof value !== "object") return false;
|
|
78
|
+
const proto = Object.getPrototypeOf(value);
|
|
79
|
+
if (proto === null) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
83
|
+
if (Ctor === Object) return true;
|
|
84
|
+
const objectCtorString = Object.prototype.constructor.toString();
|
|
85
|
+
return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
|
|
86
|
+
}
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
assertIsNotNullish,
|
|
90
|
+
assertIsNotUndefined,
|
|
91
|
+
exhaustiveCheck,
|
|
92
|
+
invariant,
|
|
93
|
+
isFunction,
|
|
94
|
+
isObject,
|
|
95
|
+
isPlainObject,
|
|
96
|
+
isPromise,
|
|
97
|
+
notNullish,
|
|
98
|
+
notUndefined
|
|
99
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type NotUndefined<T> = T extends undefined ? never : T;
|
|
2
|
+
type StrictNonUndefined<T, N = unknown> = undefined extends T ? NotUndefined<T> : N;
|
|
3
|
+
declare function notUndefined<T>(value: T): StrictNonUndefined<T>;
|
|
4
|
+
type StrictNonNullable<T, N = unknown> = undefined extends T ? NonNullable<T> : null extends T ? NonNullable<T> : N;
|
|
5
|
+
declare function notNullish<T>(value: T): StrictNonNullable<T>;
|
|
6
|
+
declare function assertIsNotNullish<T>(value: T, errorMsg?: string): asserts value is StrictNonNullable<T, never>;
|
|
7
|
+
declare function assertIsNotUndefined<T>(value: T, errorMsg?: string): asserts value is StrictNonUndefined<T, never>;
|
|
8
|
+
/** Use this function to assert that a certain condition is always true. */
|
|
9
|
+
declare function invariant(condition: any, errorMsg?: string): asserts condition;
|
|
10
|
+
/** ensures all type possibilities are being handled */
|
|
11
|
+
declare function exhaustiveCheck<Except = never>(narrowedType: NoInfer<Except>): Error;
|
|
12
|
+
declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
13
|
+
declare function isFunction(value: unknown): value is (...args: any[]) => any;
|
|
14
|
+
declare function isPromise(value: unknown): value is Promise<unknown>;
|
|
15
|
+
declare function isPlainObject(value: any): value is Record<string, unknown>;
|
|
16
|
+
|
|
17
|
+
export { assertIsNotNullish, assertIsNotUndefined, exhaustiveCheck, invariant, isFunction, isObject, isPlainObject, isPromise, notNullish, notUndefined };
|
package/dist/assertions.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
isPromise,
|
|
10
10
|
notNullish,
|
|
11
11
|
notUndefined
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-4UGSP3L3.js";
|
|
13
13
|
export {
|
|
14
14
|
assertIsNotNullish,
|
|
15
15
|
assertIsNotUndefined,
|
|
@@ -22,4 +22,3 @@ export {
|
|
|
22
22
|
notNullish,
|
|
23
23
|
notUndefined
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=assertions.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/castValues.ts
|
|
21
|
+
var castValues_exports = {};
|
|
22
|
+
__export(castValues_exports, {
|
|
23
|
+
castToNumber: () => castToNumber,
|
|
24
|
+
castToString: () => castToString
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(castValues_exports);
|
|
27
|
+
function castToString(value) {
|
|
28
|
+
return value !== null && value !== void 0 ? String(value) : null;
|
|
29
|
+
}
|
|
30
|
+
function castToNumber(value) {
|
|
31
|
+
return isNumeric(value) ? Number(value) : null;
|
|
32
|
+
}
|
|
33
|
+
function isNumeric(num) {
|
|
34
|
+
const str = String(num);
|
|
35
|
+
return !isNaN(str) && !isNaN(parseFloat(str));
|
|
36
|
+
}
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
castToNumber,
|
|
40
|
+
castToString
|
|
41
|
+
});
|
package/dist/castValues.js
CHANGED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isObject
|
|
3
|
+
} from "./chunk-4UGSP3L3.js";
|
|
4
|
+
|
|
5
|
+
// src/rsResult.ts
|
|
6
|
+
function okUnwrapOr() {
|
|
7
|
+
return this.value;
|
|
8
|
+
}
|
|
9
|
+
function ok(value = void 0) {
|
|
10
|
+
return {
|
|
11
|
+
ok: true,
|
|
12
|
+
error: false,
|
|
13
|
+
value,
|
|
14
|
+
unwrapOrNull: okUnwrapOr,
|
|
15
|
+
unwrapOr: okUnwrapOr,
|
|
16
|
+
unwrap: okUnwrapOr
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function err(error) {
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
error,
|
|
23
|
+
unwrapOrNull: () => null,
|
|
24
|
+
unwrapOr: (defaultValue) => defaultValue,
|
|
25
|
+
errorResult() {
|
|
26
|
+
return err(error);
|
|
27
|
+
},
|
|
28
|
+
unwrap: () => {
|
|
29
|
+
if (error instanceof Error) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(error)) {
|
|
33
|
+
throw new Error(error.join("\n"), { cause: error });
|
|
34
|
+
}
|
|
35
|
+
throw new Error(
|
|
36
|
+
isObject(error) && "message" in error && error.message ? String(error.message) : "Unwrap failed",
|
|
37
|
+
{ cause: error }
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function unknownToError(error) {
|
|
43
|
+
return err(normalizeError(error));
|
|
44
|
+
}
|
|
45
|
+
async function unwrap(result) {
|
|
46
|
+
const unwrapped = await result;
|
|
47
|
+
if (unwrapped.ok) {
|
|
48
|
+
return unwrapped.value;
|
|
49
|
+
}
|
|
50
|
+
throw unwrapped.error;
|
|
51
|
+
}
|
|
52
|
+
function asyncMap(resultPromise) {
|
|
53
|
+
return {
|
|
54
|
+
err: async (mapFn) => {
|
|
55
|
+
const result = await resultPromise;
|
|
56
|
+
return result.ok ? ok(result.value) : err(mapFn(result.error));
|
|
57
|
+
},
|
|
58
|
+
ok: async (mapFn) => {
|
|
59
|
+
const result = await resultPromise;
|
|
60
|
+
return result.ok ? ok(mapFn(result.value)) : err(result.error);
|
|
61
|
+
},
|
|
62
|
+
okAndErr: async ({
|
|
63
|
+
ok: mapFn,
|
|
64
|
+
err: mapErrFn
|
|
65
|
+
}) => {
|
|
66
|
+
const result = await resultPromise;
|
|
67
|
+
return result.ok ? ok(mapFn(result.value)) : err(mapErrFn(result.error));
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function syncMap(result) {
|
|
72
|
+
return {
|
|
73
|
+
err: (mapFn) => {
|
|
74
|
+
return result.ok ? ok(result.value) : err(mapFn(result.error));
|
|
75
|
+
},
|
|
76
|
+
ok: (mapFn) => {
|
|
77
|
+
return result.ok ? ok(mapFn(result.value)) : err(result.error);
|
|
78
|
+
},
|
|
79
|
+
okAndErr: ({
|
|
80
|
+
ok: mapFn,
|
|
81
|
+
err: mapErrFn
|
|
82
|
+
}) => {
|
|
83
|
+
return result.ok ? ok(mapFn(result.value)) : err(mapErrFn(result.error));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
var Result = {
|
|
88
|
+
ok,
|
|
89
|
+
err,
|
|
90
|
+
unknownToError,
|
|
91
|
+
unwrap,
|
|
92
|
+
asyncMap,
|
|
93
|
+
map: syncMap
|
|
94
|
+
};
|
|
95
|
+
function resultify(fn, errorNormalizer) {
|
|
96
|
+
try {
|
|
97
|
+
return ok(fn());
|
|
98
|
+
} catch (error) {
|
|
99
|
+
return err(
|
|
100
|
+
errorNormalizer ? errorNormalizer(error) : normalizeError(error)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function asyncResultify(fn, errorNormalizer) {
|
|
105
|
+
try {
|
|
106
|
+
return ok(await fn());
|
|
107
|
+
} catch (error) {
|
|
108
|
+
return err(
|
|
109
|
+
errorNormalizer ? errorNormalizer(error) : normalizeError(error)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function normalizeError(error) {
|
|
114
|
+
if (error instanceof Error) return error;
|
|
115
|
+
if (typeof error === "string") {
|
|
116
|
+
return new Error(error);
|
|
117
|
+
}
|
|
118
|
+
if (isObject(error)) {
|
|
119
|
+
return new Error(
|
|
120
|
+
"message" in error && error.message ? String(error.message) : safeJsonStringify(error) ?? "unknown",
|
|
121
|
+
{ cause: error }
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return new Error(safeJsonStringify(error) ?? "unknown", { cause: error });
|
|
125
|
+
}
|
|
126
|
+
function safeJsonStringify(value) {
|
|
127
|
+
try {
|
|
128
|
+
return JSON.stringify(value);
|
|
129
|
+
} catch (_) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function createTypedResult() {
|
|
134
|
+
return {
|
|
135
|
+
ok,
|
|
136
|
+
err
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
Result,
|
|
142
|
+
resultify,
|
|
143
|
+
asyncResultify,
|
|
144
|
+
normalizeError,
|
|
145
|
+
safeJsonStringify,
|
|
146
|
+
createTypedResult
|
|
147
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isFunction
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4UGSP3L3.js";
|
|
4
4
|
|
|
5
5
|
// src/enhancedMap.ts
|
|
6
6
|
var enhancedMapReject = Symbol();
|
|
@@ -73,10 +73,6 @@ var EnhancedMap = class _EnhancedMap extends Map {
|
|
|
73
73
|
toKeys() {
|
|
74
74
|
return [...this.keys()];
|
|
75
75
|
}
|
|
76
|
-
/** @deprecated, will be removed in v5 use `from` method instead */
|
|
77
|
-
static fromIterMap(array, mapFunction) {
|
|
78
|
-
return this.from(array, mapFunction);
|
|
79
|
-
}
|
|
80
76
|
static from(array, mapFunction) {
|
|
81
77
|
const map = new _EnhancedMap();
|
|
82
78
|
if (!array) return map;
|
|
@@ -102,4 +98,3 @@ export {
|
|
|
102
98
|
enhancedMapReject,
|
|
103
99
|
EnhancedMap
|
|
104
100
|
};
|
|
105
|
-
//# sourceMappingURL=chunk-4QK76IRX.js.map
|
|
@@ -12,34 +12,6 @@ function joinStrings(...args) {
|
|
|
12
12
|
}
|
|
13
13
|
return strings.join("");
|
|
14
14
|
}
|
|
15
|
-
function dedent(strings, ...values) {
|
|
16
|
-
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
17
|
-
let result = "";
|
|
18
|
-
for (let i = 0; i < raw.length; i++) {
|
|
19
|
-
result += raw[i].replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`");
|
|
20
|
-
if (i < values.length) {
|
|
21
|
-
result += values[i];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const lines = result.split("\n");
|
|
25
|
-
let mindent = null;
|
|
26
|
-
lines.forEach((l) => {
|
|
27
|
-
const m = l.match(/^(\s+)\S+/);
|
|
28
|
-
if (m) {
|
|
29
|
-
const indent = m[1].length;
|
|
30
|
-
if (!mindent) {
|
|
31
|
-
mindent = indent;
|
|
32
|
-
} else {
|
|
33
|
-
mindent = Math.min(mindent, indent);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
if (mindent !== null) {
|
|
38
|
-
const m = mindent;
|
|
39
|
-
result = lines.map((l) => l.startsWith(" ") ? l.slice(m) : l).join("\n");
|
|
40
|
-
}
|
|
41
|
-
return result.trim().replace(/\\n/g, "\n");
|
|
42
|
-
}
|
|
43
15
|
function formatNum(num) {
|
|
44
16
|
return num.toLocaleString("en-US", {
|
|
45
17
|
minimumFractionDigits: 2,
|
|
@@ -59,10 +31,8 @@ function truncateString(str, length, ellipsis = "\u2026") {
|
|
|
59
31
|
|
|
60
32
|
export {
|
|
61
33
|
joinStrings,
|
|
62
|
-
dedent,
|
|
63
34
|
formatNum,
|
|
64
35
|
isSnakeCase,
|
|
65
36
|
convertToSnakeCase,
|
|
66
37
|
truncateString
|
|
67
38
|
};
|
|
68
|
-
//# sourceMappingURL=chunk-GLZ5MZC5.js.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/consoleFmt.ts
|
|
21
|
+
var consoleFmt_exports = {};
|
|
22
|
+
__export(consoleFmt_exports, {
|
|
23
|
+
consoleFmt: () => consoleFmt
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(consoleFmt_exports);
|
|
26
|
+
var colorToCodeASCII = {
|
|
27
|
+
red: "\x1B[31m",
|
|
28
|
+
green: "\x1B[32m",
|
|
29
|
+
yellow: "\x1B[33m",
|
|
30
|
+
blue: "\x1B[34m",
|
|
31
|
+
magenta: "\x1B[35m",
|
|
32
|
+
cyan: "\x1B[36m",
|
|
33
|
+
white: "\x1B[37m",
|
|
34
|
+
black: "\x1B[30m",
|
|
35
|
+
gray: "\x1B[90m",
|
|
36
|
+
brightRed: "\x1B[91m",
|
|
37
|
+
brightGreen: "\x1B[92m",
|
|
38
|
+
brightYellow: "\x1B[93m",
|
|
39
|
+
brightBlue: "\x1B[94m",
|
|
40
|
+
brightMagenta: "\x1B[95m",
|
|
41
|
+
brightCyan: "\x1B[96m",
|
|
42
|
+
brightWhite: "\x1B[97m"
|
|
43
|
+
};
|
|
44
|
+
function consoleColors(color, text) {
|
|
45
|
+
return `${colorToCodeASCII[color]}${text}\x1B[0m`;
|
|
46
|
+
}
|
|
47
|
+
function bold(text) {
|
|
48
|
+
return `\x1B[1m${text}\x1B[0m`;
|
|
49
|
+
}
|
|
50
|
+
function underline(text) {
|
|
51
|
+
return `\x1B[4m${text}\x1B[0m`;
|
|
52
|
+
}
|
|
53
|
+
var bgColorToCodeASCII = {
|
|
54
|
+
red: "\x1B[41m",
|
|
55
|
+
green: "\x1B[42m",
|
|
56
|
+
yellow: "\x1B[43m",
|
|
57
|
+
blue: "\x1B[44m",
|
|
58
|
+
magenta: "\x1B[45m",
|
|
59
|
+
cyan: "\x1B[46m",
|
|
60
|
+
white: "\x1B[47m",
|
|
61
|
+
black: "\x1B[40m",
|
|
62
|
+
gray: "\x1B[100m",
|
|
63
|
+
brightRed: "\x1B[101m",
|
|
64
|
+
brightGreen: "\x1B[102m",
|
|
65
|
+
brightYellow: "\x1B[103m",
|
|
66
|
+
brightBlue: "\x1B[104m",
|
|
67
|
+
brightMagenta: "\x1B[105m",
|
|
68
|
+
brightCyan: "\x1B[106m",
|
|
69
|
+
brightWhite: "\x1B[107m"
|
|
70
|
+
};
|
|
71
|
+
function bgColor(color, text) {
|
|
72
|
+
const resetBgColor = "\x1B[49m";
|
|
73
|
+
return `${bgColorToCodeASCII[color]}${text}${resetBgColor}\x1B[0m`;
|
|
74
|
+
}
|
|
75
|
+
var consoleFmt = {
|
|
76
|
+
color: consoleColors,
|
|
77
|
+
bold,
|
|
78
|
+
underline,
|
|
79
|
+
bgColor
|
|
80
|
+
};
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
consoleFmt
|
|
84
|
+
});
|