@ls-stack/utils 2.14.1 → 3.2.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/assertions.cjs +5 -5
- package/dist/assertions.d.cts +2 -2
- package/dist/assertions.d.ts +2 -2
- package/dist/assertions.js +1 -1
- package/dist/cache.cjs +4 -1
- package/dist/cache.js +3 -3
- package/dist/castValues.cjs +12 -4
- package/dist/castValues.js +1 -1
- package/dist/{chunk-4UGSP3L3.js → chunk-3XCS7FVO.js} +5 -5
- package/dist/{chunk-RK6PT7JY.js → chunk-5MNYPLZI.js} +1 -1
- package/dist/chunk-II4R3VVX.js +25 -0
- package/dist/{chunk-KBFP7INB.js → chunk-J73KJABC.js} +67 -38
- package/dist/{chunk-T5WDDPFI.js → chunk-OHHF4CJZ.js} +1 -1
- package/dist/createThrottleController.js +4 -4
- package/dist/enhancedMap.js +2 -2
- package/dist/exhaustiveMatch.cjs +13 -2
- package/dist/exhaustiveMatch.d.cts +4 -1
- package/dist/exhaustiveMatch.d.ts +4 -1
- package/dist/exhaustiveMatch.js +11 -1
- package/dist/getValueStableKey.cjs +83 -0
- package/dist/getValueStableKey.d.cts +10 -0
- package/dist/getValueStableKey.d.ts +10 -0
- package/dist/getValueStableKey.js +55 -0
- package/dist/interpolate.js +1 -1
- package/dist/main.d.ts +2 -4
- package/dist/parallelAsyncCalls.cjs +51 -18
- package/dist/parallelAsyncCalls.d.cts +1 -2
- package/dist/parallelAsyncCalls.d.ts +1 -2
- package/dist/parallelAsyncCalls.js +5 -5
- package/dist/testUtils.js +1 -1
- package/dist/time.cjs +12 -4
- package/dist/time.js +2 -2
- package/dist/{rsResult.cjs → tsResult.cjs} +74 -43
- package/dist/{rsResult.d.cts → tsResult.d.cts} +34 -23
- package/dist/{rsResult.d.ts → tsResult.d.ts} +34 -23
- package/dist/tsResult.js +16 -0
- package/dist/typingTestUtils.cjs +4 -1
- package/dist/typingTestUtils.d.cts +26 -0
- package/dist/typingTestUtils.d.ts +26 -0
- package/dist/typingTestUtils.js +4 -1
- package/dist/typingUtils.d.cts +4 -1
- package/dist/typingUtils.d.ts +4 -1
- package/dist/yamlStringify.js +1 -1
- package/package.json +15 -31
- package/dist/chunk-GBFS2I67.js +0 -17
- package/dist/getObjStableKey.cjs +0 -83
- package/dist/getObjStableKey.d.cts +0 -3
- package/dist/getObjStableKey.d.ts +0 -3
- package/dist/getObjStableKey.js +0 -44
- package/dist/rsResult.js +0 -20
package/dist/assertions.cjs
CHANGED
|
@@ -34,15 +34,15 @@ __export(assertions_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(assertions_exports);
|
|
35
35
|
var undefErrMsg = "not undefined assertion failed";
|
|
36
36
|
var nullishErrMsg = "not nullish assertion failed";
|
|
37
|
-
function notUndefined(value) {
|
|
37
|
+
function notUndefined(value, errorMsg = undefErrMsg) {
|
|
38
38
|
if (value === void 0) {
|
|
39
|
-
throw new Error(
|
|
39
|
+
throw new Error(errorMsg);
|
|
40
40
|
}
|
|
41
41
|
return value;
|
|
42
42
|
}
|
|
43
|
-
function notNullish(value) {
|
|
43
|
+
function notNullish(value, errorMsg = nullishErrMsg) {
|
|
44
44
|
if (value === void 0 || value === null) {
|
|
45
|
-
throw new Error(
|
|
45
|
+
throw new Error(errorMsg);
|
|
46
46
|
}
|
|
47
47
|
return value;
|
|
48
48
|
}
|
|
@@ -71,7 +71,7 @@ function isFunction(value) {
|
|
|
71
71
|
return typeof value === "function";
|
|
72
72
|
}
|
|
73
73
|
function isPromise(value) {
|
|
74
|
-
return isObject(value) && "then" in value;
|
|
74
|
+
return isObject(value) && "then" in value && isFunction(value.then);
|
|
75
75
|
}
|
|
76
76
|
function isPlainObject(value) {
|
|
77
77
|
if (!value || typeof value !== "object") return false;
|
package/dist/assertions.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
type NotUndefined<T> = T extends undefined ? never : T;
|
|
2
2
|
type StrictNonUndefined<T, N = unknown> = undefined extends T ? NotUndefined<T> : N;
|
|
3
|
-
declare function notUndefined<T>(value: T): StrictNonUndefined<T>;
|
|
3
|
+
declare function notUndefined<T>(value: T, errorMsg?: string): StrictNonUndefined<T>;
|
|
4
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>;
|
|
5
|
+
declare function notNullish<T>(value: T, errorMsg?: string): StrictNonNullable<T>;
|
|
6
6
|
declare function assertIsNotNullish<T>(value: T, errorMsg?: string): asserts value is StrictNonNullable<T, never>;
|
|
7
7
|
declare function assertIsNotUndefined<T>(value: T, errorMsg?: string): asserts value is StrictNonUndefined<T, never>;
|
|
8
8
|
/** Use this function to assert that a certain condition is always true. */
|
package/dist/assertions.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
type NotUndefined<T> = T extends undefined ? never : T;
|
|
2
2
|
type StrictNonUndefined<T, N = unknown> = undefined extends T ? NotUndefined<T> : N;
|
|
3
|
-
declare function notUndefined<T>(value: T): StrictNonUndefined<T>;
|
|
3
|
+
declare function notUndefined<T>(value: T, errorMsg?: string): StrictNonUndefined<T>;
|
|
4
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>;
|
|
5
|
+
declare function notNullish<T>(value: T, errorMsg?: string): StrictNonNullable<T>;
|
|
6
6
|
declare function assertIsNotNullish<T>(value: T, errorMsg?: string): asserts value is StrictNonNullable<T, never>;
|
|
7
7
|
declare function assertIsNotUndefined<T>(value: T, errorMsg?: string): asserts value is StrictNonUndefined<T, never>;
|
|
8
8
|
/** Use this function to assert that a certain condition is always true. */
|
package/dist/assertions.js
CHANGED
package/dist/cache.cjs
CHANGED
|
@@ -31,8 +31,11 @@ module.exports = __toCommonJS(cache_exports);
|
|
|
31
31
|
function isObject(value) {
|
|
32
32
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
33
|
}
|
|
34
|
+
function isFunction(value) {
|
|
35
|
+
return typeof value === "function";
|
|
36
|
+
}
|
|
34
37
|
function isPromise(value) {
|
|
35
|
-
return isObject(value) && "then" in value;
|
|
38
|
+
return isObject(value) && "then" in value && isFunction(value.then);
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
// src/time.ts
|
package/dist/cache.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
durationObjToMs
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5MNYPLZI.js";
|
|
4
4
|
import "./chunk-HTCYUMDR.js";
|
|
5
5
|
import {
|
|
6
6
|
isPromise
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-3XCS7FVO.js";
|
|
8
|
+
import "./chunk-II4R3VVX.js";
|
|
9
9
|
|
|
10
10
|
// src/cache.ts
|
|
11
11
|
function cachedGetter(getter) {
|
package/dist/castValues.cjs
CHANGED
|
@@ -29,11 +29,19 @@ function castToString(value) {
|
|
|
29
29
|
return valueType === "string" || valueType === "number" || valueType === "boolean" || valueType === "bigint" ? String(value) : null;
|
|
30
30
|
}
|
|
31
31
|
function castToNumber(value) {
|
|
32
|
-
return
|
|
32
|
+
return isFiniteNumeric(value) ? Number(value) : null;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
function isFiniteNumeric(num) {
|
|
35
|
+
switch (typeof num) {
|
|
36
|
+
case "number":
|
|
37
|
+
return num - num === 0;
|
|
38
|
+
case "string":
|
|
39
|
+
return num.trim() !== "" && Number.isFinite(+num);
|
|
40
|
+
case "bigint":
|
|
41
|
+
return Number.isFinite(Number(num));
|
|
42
|
+
default:
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
37
45
|
}
|
|
38
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
47
|
0 && (module.exports = {
|
package/dist/castValues.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// src/assertions.ts
|
|
2
2
|
var undefErrMsg = "not undefined assertion failed";
|
|
3
3
|
var nullishErrMsg = "not nullish assertion failed";
|
|
4
|
-
function notUndefined(value) {
|
|
4
|
+
function notUndefined(value, errorMsg = undefErrMsg) {
|
|
5
5
|
if (value === void 0) {
|
|
6
|
-
throw new Error(
|
|
6
|
+
throw new Error(errorMsg);
|
|
7
7
|
}
|
|
8
8
|
return value;
|
|
9
9
|
}
|
|
10
|
-
function notNullish(value) {
|
|
10
|
+
function notNullish(value, errorMsg = nullishErrMsg) {
|
|
11
11
|
if (value === void 0 || value === null) {
|
|
12
|
-
throw new Error(
|
|
12
|
+
throw new Error(errorMsg);
|
|
13
13
|
}
|
|
14
14
|
return value;
|
|
15
15
|
}
|
|
@@ -38,7 +38,7 @@ function isFunction(value) {
|
|
|
38
38
|
return typeof value === "function";
|
|
39
39
|
}
|
|
40
40
|
function isPromise(value) {
|
|
41
|
-
return isObject(value) && "then" in value;
|
|
41
|
+
return isObject(value) && "then" in value && isFunction(value.then);
|
|
42
42
|
}
|
|
43
43
|
function isPlainObject(value) {
|
|
44
44
|
if (!value || typeof value !== "object") return false;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/castValues.ts
|
|
2
|
+
function castToString(value) {
|
|
3
|
+
const valueType = typeof value;
|
|
4
|
+
return valueType === "string" || valueType === "number" || valueType === "boolean" || valueType === "bigint" ? String(value) : null;
|
|
5
|
+
}
|
|
6
|
+
function castToNumber(value) {
|
|
7
|
+
return isFiniteNumeric(value) ? Number(value) : null;
|
|
8
|
+
}
|
|
9
|
+
function isFiniteNumeric(num) {
|
|
10
|
+
switch (typeof num) {
|
|
11
|
+
case "number":
|
|
12
|
+
return num - num === 0;
|
|
13
|
+
case "string":
|
|
14
|
+
return num.trim() !== "" && Number.isFinite(+num);
|
|
15
|
+
case "bigint":
|
|
16
|
+
return Number.isFinite(Number(num));
|
|
17
|
+
default:
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
castToString,
|
|
24
|
+
castToNumber
|
|
25
|
+
};
|
|
@@ -2,10 +2,12 @@ import {
|
|
|
2
2
|
safeJsonStringify
|
|
3
3
|
} from "./chunk-VAAMRG4K.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
isFunction,
|
|
6
|
+
isObject,
|
|
7
|
+
isPromise
|
|
8
|
+
} from "./chunk-3XCS7FVO.js";
|
|
7
9
|
|
|
8
|
-
// src/
|
|
10
|
+
// src/tsResult.ts
|
|
9
11
|
function okUnwrapOr() {
|
|
10
12
|
return this.value;
|
|
11
13
|
}
|
|
@@ -24,28 +26,40 @@ function mapOkAndErr({
|
|
|
24
26
|
function returnResult() {
|
|
25
27
|
return this;
|
|
26
28
|
}
|
|
29
|
+
function okOnOk(fn) {
|
|
30
|
+
if (this.ok) {
|
|
31
|
+
fn(this.value);
|
|
32
|
+
}
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
function errOnErr(fn) {
|
|
36
|
+
if (!this.ok) {
|
|
37
|
+
fn(this.error);
|
|
38
|
+
}
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
27
41
|
function ok(value = void 0) {
|
|
28
|
-
|
|
29
|
-
ok: true,
|
|
30
|
-
error: false,
|
|
31
|
-
value,
|
|
42
|
+
const methods = {
|
|
32
43
|
unwrapOrNull: okUnwrapOr,
|
|
33
44
|
unwrapOr: okUnwrapOr,
|
|
34
45
|
unwrap: okUnwrapOr,
|
|
35
46
|
mapOk: okMap,
|
|
36
47
|
mapErr: returnResult,
|
|
37
|
-
mapOkAndErr
|
|
48
|
+
mapOkAndErr,
|
|
49
|
+
ifOk: okOnOk,
|
|
50
|
+
ifErr: returnResult
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
ok: true,
|
|
54
|
+
error: false,
|
|
55
|
+
value,
|
|
56
|
+
...methods
|
|
38
57
|
};
|
|
39
58
|
}
|
|
40
59
|
function err(error) {
|
|
41
|
-
|
|
42
|
-
ok: false,
|
|
43
|
-
error,
|
|
60
|
+
const methods = {
|
|
44
61
|
unwrapOrNull: () => null,
|
|
45
62
|
unwrapOr: (defaultValue) => defaultValue,
|
|
46
|
-
errorResult() {
|
|
47
|
-
return err(error);
|
|
48
|
-
},
|
|
49
63
|
unwrap: () => {
|
|
50
64
|
if (error instanceof Error) {
|
|
51
65
|
throw error;
|
|
@@ -54,7 +68,17 @@ function err(error) {
|
|
|
54
68
|
},
|
|
55
69
|
mapOk: returnResult,
|
|
56
70
|
mapErr: errMap,
|
|
57
|
-
mapOkAndErr
|
|
71
|
+
mapOkAndErr,
|
|
72
|
+
ifOk: returnResult,
|
|
73
|
+
ifErr: errOnErr
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
ok: false,
|
|
77
|
+
error,
|
|
78
|
+
errorResult() {
|
|
79
|
+
return err(error);
|
|
80
|
+
},
|
|
81
|
+
...methods
|
|
58
82
|
};
|
|
59
83
|
}
|
|
60
84
|
function unknownToResultError(error) {
|
|
@@ -94,20 +118,27 @@ var Result = {
|
|
|
94
118
|
err,
|
|
95
119
|
unknownToError: unknownToResultError,
|
|
96
120
|
asyncUnwrap,
|
|
97
|
-
asyncMap
|
|
121
|
+
asyncMap,
|
|
122
|
+
getOkErr
|
|
98
123
|
};
|
|
99
124
|
function resultify(fn, errorNormalizer) {
|
|
100
|
-
|
|
101
|
-
return
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
125
|
+
if (!isFunction(fn)) {
|
|
126
|
+
return fn.then((value) => ok(value)).catch(
|
|
127
|
+
(error) => err(
|
|
128
|
+
errorNormalizer ? errorNormalizer(error) : unknownToError(error)
|
|
129
|
+
)
|
|
105
130
|
);
|
|
106
131
|
}
|
|
107
|
-
}
|
|
108
|
-
async function asyncResultify(fn, errorNormalizer) {
|
|
109
132
|
try {
|
|
110
|
-
|
|
133
|
+
const result = fn();
|
|
134
|
+
if (isPromise(result)) {
|
|
135
|
+
return result.then((value) => ok(value)).catch(
|
|
136
|
+
(error) => err(
|
|
137
|
+
errorNormalizer ? errorNormalizer(error) : unknownToError(error)
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
return ok(result);
|
|
111
142
|
} catch (error) {
|
|
112
143
|
return err(
|
|
113
144
|
errorNormalizer ? errorNormalizer(error) : unknownToError(error)
|
|
@@ -129,23 +160,21 @@ function unknownToError(error) {
|
|
|
129
160
|
cause: error
|
|
130
161
|
});
|
|
131
162
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
163
|
+
var typedResult = {
|
|
164
|
+
ok,
|
|
165
|
+
err,
|
|
166
|
+
get _type() {
|
|
167
|
+
throw new Error("usage as value is not allowed");
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
function getOkErr() {
|
|
171
|
+
return typedResult;
|
|
141
172
|
}
|
|
142
173
|
|
|
143
174
|
export {
|
|
175
|
+
ok,
|
|
176
|
+
err,
|
|
144
177
|
Result,
|
|
145
178
|
resultify,
|
|
146
|
-
|
|
147
|
-
unknownToError,
|
|
148
|
-
normalizeError,
|
|
149
|
-
safeJsonStringify2 as safeJsonStringify,
|
|
150
|
-
createTypedResult
|
|
179
|
+
unknownToError
|
|
151
180
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EnhancedMap
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OHHF4CJZ.js";
|
|
4
4
|
import {
|
|
5
5
|
durationObjToMs
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5MNYPLZI.js";
|
|
7
7
|
import "./chunk-HTCYUMDR.js";
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
8
|
+
import "./chunk-3XCS7FVO.js";
|
|
9
|
+
import "./chunk-II4R3VVX.js";
|
|
10
10
|
|
|
11
11
|
// src/createThrottleController.ts
|
|
12
12
|
function createThrottleController({
|
package/dist/enhancedMap.js
CHANGED
package/dist/exhaustiveMatch.cjs
CHANGED
|
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/exhaustiveMatch.ts
|
|
21
21
|
var exhaustiveMatch_exports = {};
|
|
22
22
|
__export(exhaustiveMatch_exports, {
|
|
23
|
-
exhaustiveMatch: () => exhaustiveMatch
|
|
23
|
+
exhaustiveMatch: () => exhaustiveMatch,
|
|
24
|
+
exhaustiveMatchObjUnion: () => exhaustiveMatchObjUnion
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(exhaustiveMatch_exports);
|
|
26
27
|
function exhaustiveMatch(value) {
|
|
@@ -49,7 +50,17 @@ function exhaustiveMatch(value) {
|
|
|
49
50
|
withObject
|
|
50
51
|
};
|
|
51
52
|
}
|
|
53
|
+
function exhaustiveMatchObjUnion(obj, key) {
|
|
54
|
+
function withLazy(pattern) {
|
|
55
|
+
const result = pattern[obj[key]];
|
|
56
|
+
if (typeof result === "function")
|
|
57
|
+
return result(obj);
|
|
58
|
+
throw new Error(`Exhaustive match failed: no match for ${obj[key]}`);
|
|
59
|
+
}
|
|
60
|
+
return { with: withLazy };
|
|
61
|
+
}
|
|
52
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
63
|
0 && (module.exports = {
|
|
54
|
-
exhaustiveMatch
|
|
64
|
+
exhaustiveMatch,
|
|
65
|
+
exhaustiveMatchObjUnion
|
|
55
66
|
});
|
|
@@ -2,5 +2,8 @@ declare function exhaustiveMatch<T extends string>(value: T): {
|
|
|
2
2
|
with: <R>(pattern: { [K in T]: "_nxt" | "_never" | (() => R); }) => R;
|
|
3
3
|
withObject: <R>(pattern: Record<T, R>) => R;
|
|
4
4
|
};
|
|
5
|
+
declare function exhaustiveMatchObjUnion<T extends Record<string, unknown>, D extends keyof T, K extends T[D] & string>(obj: T, key: D): {
|
|
6
|
+
with: <R>(pattern: { [P in K]: "_never" | ((props: Extract<T, Record<D, P>>) => R); }) => R;
|
|
7
|
+
};
|
|
5
8
|
|
|
6
|
-
export { exhaustiveMatch };
|
|
9
|
+
export { exhaustiveMatch, exhaustiveMatchObjUnion };
|
|
@@ -2,5 +2,8 @@ declare function exhaustiveMatch<T extends string>(value: T): {
|
|
|
2
2
|
with: <R>(pattern: { [K in T]: "_nxt" | "_never" | (() => R); }) => R;
|
|
3
3
|
withObject: <R>(pattern: Record<T, R>) => R;
|
|
4
4
|
};
|
|
5
|
+
declare function exhaustiveMatchObjUnion<T extends Record<string, unknown>, D extends keyof T, K extends T[D] & string>(obj: T, key: D): {
|
|
6
|
+
with: <R>(pattern: { [P in K]: "_never" | ((props: Extract<T, Record<D, P>>) => R); }) => R;
|
|
7
|
+
};
|
|
5
8
|
|
|
6
|
-
export { exhaustiveMatch };
|
|
9
|
+
export { exhaustiveMatch, exhaustiveMatchObjUnion };
|
package/dist/exhaustiveMatch.js
CHANGED
|
@@ -25,6 +25,16 @@ function exhaustiveMatch(value) {
|
|
|
25
25
|
withObject
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
function exhaustiveMatchObjUnion(obj, key) {
|
|
29
|
+
function withLazy(pattern) {
|
|
30
|
+
const result = pattern[obj[key]];
|
|
31
|
+
if (typeof result === "function")
|
|
32
|
+
return result(obj);
|
|
33
|
+
throw new Error(`Exhaustive match failed: no match for ${obj[key]}`);
|
|
34
|
+
}
|
|
35
|
+
return { with: withLazy };
|
|
36
|
+
}
|
|
28
37
|
export {
|
|
29
|
-
exhaustiveMatch
|
|
38
|
+
exhaustiveMatch,
|
|
39
|
+
exhaustiveMatchObjUnion
|
|
30
40
|
};
|
|
@@ -0,0 +1,83 @@
|
|
|
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/getValueStableKey.ts
|
|
21
|
+
var getValueStableKey_exports = {};
|
|
22
|
+
__export(getValueStableKey_exports, {
|
|
23
|
+
getValueStableKey: () => getValueStableKey
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(getValueStableKey_exports);
|
|
26
|
+
|
|
27
|
+
// src/assertions.ts
|
|
28
|
+
function isObject(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/getValueStableKey.ts
|
|
33
|
+
function getValueStableKey(input, maxSortingDepth = 3) {
|
|
34
|
+
if (typeof input === "string") return `"${input}`;
|
|
35
|
+
if (!input || typeof input !== "object") return `$${input}`;
|
|
36
|
+
return stringifyCompact(input, maxSortingDepth, 0, /* @__PURE__ */ new WeakSet());
|
|
37
|
+
}
|
|
38
|
+
function stringifyCompact(input, maxSortingDepth, depth, refs) {
|
|
39
|
+
const isJsObj = input && typeof input === "object";
|
|
40
|
+
if (isJsObj) {
|
|
41
|
+
if (refs.has(input)) {
|
|
42
|
+
throw new Error("Circular reference detected");
|
|
43
|
+
}
|
|
44
|
+
refs.add(input);
|
|
45
|
+
}
|
|
46
|
+
let result;
|
|
47
|
+
if (Array.isArray(input)) {
|
|
48
|
+
result = "[";
|
|
49
|
+
for (const v of input) {
|
|
50
|
+
if (result.length > 1) result += ",";
|
|
51
|
+
result += stringifyCompact(v, maxSortingDepth, depth + 1, refs);
|
|
52
|
+
}
|
|
53
|
+
result += "]";
|
|
54
|
+
} else if (isObject(input)) {
|
|
55
|
+
let entries = Object.entries(input);
|
|
56
|
+
if (entries.length === 0) {
|
|
57
|
+
result = "{}";
|
|
58
|
+
} else {
|
|
59
|
+
if (depth < maxSortingDepth) {
|
|
60
|
+
entries = entries.sort(
|
|
61
|
+
([a], [b]) => a < b ? -1 : a > b ? 1 : 0
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
result = "{";
|
|
65
|
+
for (const [k, v] of entries) {
|
|
66
|
+
if (v === void 0) continue;
|
|
67
|
+
if (result.length > 1) result += ",";
|
|
68
|
+
result += `${k}:${stringifyCompact(v, maxSortingDepth, depth + 1, refs)}`;
|
|
69
|
+
}
|
|
70
|
+
result += "}";
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
result = JSON.stringify(input);
|
|
74
|
+
}
|
|
75
|
+
if (isJsObj) {
|
|
76
|
+
refs.delete(input);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
getValueStableKey
|
|
83
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a stable key for the input value.
|
|
3
|
+
*
|
|
4
|
+
* @param input - The value to get a stable key for.
|
|
5
|
+
* @param maxSortingDepth - The maximum depth to sort the input value. Default is 3.
|
|
6
|
+
* @returns A stable key for the input value.
|
|
7
|
+
*/
|
|
8
|
+
declare function getValueStableKey(input: unknown, maxSortingDepth?: number): string;
|
|
9
|
+
|
|
10
|
+
export { getValueStableKey };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a stable key for the input value.
|
|
3
|
+
*
|
|
4
|
+
* @param input - The value to get a stable key for.
|
|
5
|
+
* @param maxSortingDepth - The maximum depth to sort the input value. Default is 3.
|
|
6
|
+
* @returns A stable key for the input value.
|
|
7
|
+
*/
|
|
8
|
+
declare function getValueStableKey(input: unknown, maxSortingDepth?: number): string;
|
|
9
|
+
|
|
10
|
+
export { getValueStableKey };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isObject
|
|
3
|
+
} from "./chunk-3XCS7FVO.js";
|
|
4
|
+
|
|
5
|
+
// src/getValueStableKey.ts
|
|
6
|
+
function getValueStableKey(input, maxSortingDepth = 3) {
|
|
7
|
+
if (typeof input === "string") return `"${input}`;
|
|
8
|
+
if (!input || typeof input !== "object") return `$${input}`;
|
|
9
|
+
return stringifyCompact(input, maxSortingDepth, 0, /* @__PURE__ */ new WeakSet());
|
|
10
|
+
}
|
|
11
|
+
function stringifyCompact(input, maxSortingDepth, depth, refs) {
|
|
12
|
+
const isJsObj = input && typeof input === "object";
|
|
13
|
+
if (isJsObj) {
|
|
14
|
+
if (refs.has(input)) {
|
|
15
|
+
throw new Error("Circular reference detected");
|
|
16
|
+
}
|
|
17
|
+
refs.add(input);
|
|
18
|
+
}
|
|
19
|
+
let result;
|
|
20
|
+
if (Array.isArray(input)) {
|
|
21
|
+
result = "[";
|
|
22
|
+
for (const v of input) {
|
|
23
|
+
if (result.length > 1) result += ",";
|
|
24
|
+
result += stringifyCompact(v, maxSortingDepth, depth + 1, refs);
|
|
25
|
+
}
|
|
26
|
+
result += "]";
|
|
27
|
+
} else if (isObject(input)) {
|
|
28
|
+
let entries = Object.entries(input);
|
|
29
|
+
if (entries.length === 0) {
|
|
30
|
+
result = "{}";
|
|
31
|
+
} else {
|
|
32
|
+
if (depth < maxSortingDepth) {
|
|
33
|
+
entries = entries.sort(
|
|
34
|
+
([a], [b]) => a < b ? -1 : a > b ? 1 : 0
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
result = "{";
|
|
38
|
+
for (const [k, v] of entries) {
|
|
39
|
+
if (v === void 0) continue;
|
|
40
|
+
if (result.length > 1) result += ",";
|
|
41
|
+
result += `${k}:${stringifyCompact(v, maxSortingDepth, depth + 1, refs)}`;
|
|
42
|
+
}
|
|
43
|
+
result += "}";
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
result = JSON.stringify(input);
|
|
47
|
+
}
|
|
48
|
+
if (isJsObj) {
|
|
49
|
+
refs.delete(input);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
getValueStableKey
|
|
55
|
+
};
|
package/dist/interpolate.js
CHANGED
package/dist/main.d.ts
CHANGED
|
@@ -10,17 +10,14 @@
|
|
|
10
10
|
///<reference path="deepEqual.d.ts" />
|
|
11
11
|
///<reference path="enhancedMap.d.ts" />
|
|
12
12
|
///<reference path="exhaustiveMatch.d.ts" />
|
|
13
|
-
///<reference path="
|
|
14
|
-
///<reference path="internalUtils.d.ts" />
|
|
13
|
+
///<reference path="getValueStableKey.d.ts" />
|
|
15
14
|
///<reference path="interpolate.d.ts" />
|
|
16
15
|
///<reference path="levenshtein.d.ts" />
|
|
17
|
-
///<reference path="main.d.ts" />
|
|
18
16
|
///<reference path="mathUtils.d.ts" />
|
|
19
17
|
///<reference path="objUtils.d.ts" />
|
|
20
18
|
///<reference path="parallelAsyncCalls.d.ts" />
|
|
21
19
|
///<reference path="promiseUtils.d.ts" />
|
|
22
20
|
///<reference path="retryOnError.d.ts" />
|
|
23
|
-
///<reference path="rsResult.d.ts" />
|
|
24
21
|
///<reference path="runShellCmd.d.ts" />
|
|
25
22
|
///<reference path="safeJson.d.ts" />
|
|
26
23
|
///<reference path="shallowEqual.d.ts" />
|
|
@@ -28,6 +25,7 @@
|
|
|
28
25
|
///<reference path="stringUtils.d.ts" />
|
|
29
26
|
///<reference path="testUtils.d.ts" />
|
|
30
27
|
///<reference path="time.d.ts" />
|
|
28
|
+
///<reference path="tsResult.d.ts" />
|
|
31
29
|
///<reference path="typingFnUtils.d.ts" />
|
|
32
30
|
///<reference path="typingTestUtils.d.ts" />
|
|
33
31
|
///<reference path="typingUtils.d.ts" />
|