@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
|
@@ -2,11 +2,37 @@ type TestTypeIsEqual<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T e
|
|
|
2
2
|
type TestTypeNotEqual<X, Y> = true extends TestTypeIsEqual<X, Y> ? false : true;
|
|
3
3
|
declare function test(title: string, func: () => any): void;
|
|
4
4
|
declare function describe(title: string, func: () => any): void;
|
|
5
|
+
/**
|
|
6
|
+
* Helper function for type testing that ensures a type extends `true`.
|
|
7
|
+
* Used in combination with `TestTypeIsEqual` to verify type equality at compile time.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* expectType<TestTypeIsEqual<string, string>>(); // OK
|
|
11
|
+
* expectType<TestTypeIsEqual<string, number>>(); // Type error
|
|
12
|
+
*
|
|
13
|
+
* @template T Type that must extend `true`
|
|
14
|
+
* @returns An empty object cast to type T
|
|
15
|
+
*/
|
|
5
16
|
declare function expectType<T extends true>(): T;
|
|
17
|
+
/**
|
|
18
|
+
* Helper function for type testing that compares two types and expects a specific result.
|
|
19
|
+
* This function allows for more explicit type equality assertions with a descriptive result.
|
|
20
|
+
*
|
|
21
|
+
* @template X First type to compare
|
|
22
|
+
* @template Y Second type to compare
|
|
23
|
+
* @param result Expected comparison result: 'equal' if types are equal, 'notEqual' if they differ
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* expectTypesAre<string, string>('equal'); // OK
|
|
27
|
+
* expectTypesAre<string, number>('notEqual'); // OK
|
|
28
|
+
* expectTypesAre<string, string>('notEqual'); // Type error
|
|
29
|
+
*/
|
|
30
|
+
declare function expectTypesAre<X, Y>(result: TestTypeIsEqual<X, Y> extends true ? 'equal' : 'notEqual'): void;
|
|
6
31
|
declare const typingTest: {
|
|
7
32
|
test: typeof test;
|
|
8
33
|
describe: typeof describe;
|
|
9
34
|
expectType: typeof expectType;
|
|
35
|
+
expectTypesAre: typeof expectTypesAre;
|
|
10
36
|
};
|
|
11
37
|
|
|
12
38
|
export { type TestTypeIsEqual, type TestTypeNotEqual, typingTest };
|
package/dist/typingTestUtils.js
CHANGED
package/dist/typingUtils.d.cts
CHANGED
|
@@ -7,5 +7,8 @@ type NonPartial<T> = {
|
|
|
7
7
|
type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType> = {
|
|
8
8
|
[K in keyof Obj]: Obj[K] extends ValueType ? K : never;
|
|
9
9
|
}[keyof Obj];
|
|
10
|
+
type IsAny<T> = unknown extends T ? [
|
|
11
|
+
keyof T
|
|
12
|
+
] extends [never] ? false : true : false;
|
|
10
13
|
|
|
11
|
-
export type { NonPartial, ObjKeysWithValuesOfType, PartialRecord };
|
|
14
|
+
export type { IsAny, NonPartial, ObjKeysWithValuesOfType, PartialRecord };
|
package/dist/typingUtils.d.ts
CHANGED
|
@@ -7,5 +7,8 @@ type NonPartial<T> = {
|
|
|
7
7
|
type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType> = {
|
|
8
8
|
[K in keyof Obj]: Obj[K] extends ValueType ? K : never;
|
|
9
9
|
}[keyof Obj];
|
|
10
|
+
type IsAny<T> = unknown extends T ? [
|
|
11
|
+
keyof T
|
|
12
|
+
] extends [never] ? false : true : false;
|
|
10
13
|
|
|
11
|
-
export type { NonPartial, ObjKeysWithValuesOfType, PartialRecord };
|
|
14
|
+
export type { IsAny, NonPartial, ObjKeysWithValuesOfType, PartialRecord };
|
package/dist/yamlStringify.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-stack/utils",
|
|
3
3
|
"description": "Typescript utils",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "3.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -79,15 +79,10 @@
|
|
|
79
79
|
"types": "./dist/exhaustiveMatch.d.ts",
|
|
80
80
|
"require": "./dist/exhaustiveMatch.cjs"
|
|
81
81
|
},
|
|
82
|
-
"./
|
|
83
|
-
"import": "./dist/
|
|
84
|
-
"types": "./dist/
|
|
85
|
-
"require": "./dist/
|
|
86
|
-
},
|
|
87
|
-
"./internalUtils": {
|
|
88
|
-
"import": "./dist/internalUtils.js",
|
|
89
|
-
"types": "./dist/internalUtils.d.ts",
|
|
90
|
-
"require": "./dist/internalUtils.cjs"
|
|
82
|
+
"./getValueStableKey": {
|
|
83
|
+
"import": "./dist/getValueStableKey.js",
|
|
84
|
+
"types": "./dist/getValueStableKey.d.ts",
|
|
85
|
+
"require": "./dist/getValueStableKey.cjs"
|
|
91
86
|
},
|
|
92
87
|
"./interpolate": {
|
|
93
88
|
"import": "./dist/interpolate.js",
|
|
@@ -99,11 +94,6 @@
|
|
|
99
94
|
"types": "./dist/levenshtein.d.ts",
|
|
100
95
|
"require": "./dist/levenshtein.cjs"
|
|
101
96
|
},
|
|
102
|
-
"./main": {
|
|
103
|
-
"import": "./dist/main.js",
|
|
104
|
-
"types": "./dist/main.d.ts",
|
|
105
|
-
"require": "./dist/main.cjs"
|
|
106
|
-
},
|
|
107
97
|
"./mathUtils": {
|
|
108
98
|
"import": "./dist/mathUtils.js",
|
|
109
99
|
"types": "./dist/mathUtils.d.ts",
|
|
@@ -129,11 +119,6 @@
|
|
|
129
119
|
"types": "./dist/retryOnError.d.ts",
|
|
130
120
|
"require": "./dist/retryOnError.cjs"
|
|
131
121
|
},
|
|
132
|
-
"./rsResult": {
|
|
133
|
-
"import": "./dist/rsResult.js",
|
|
134
|
-
"types": "./dist/rsResult.d.ts",
|
|
135
|
-
"require": "./dist/rsResult.cjs"
|
|
136
|
-
},
|
|
137
122
|
"./runShellCmd": {
|
|
138
123
|
"import": "./dist/runShellCmd.js",
|
|
139
124
|
"types": "./dist/runShellCmd.d.ts",
|
|
@@ -169,6 +154,11 @@
|
|
|
169
154
|
"types": "./dist/time.d.ts",
|
|
170
155
|
"require": "./dist/time.cjs"
|
|
171
156
|
},
|
|
157
|
+
"./tsResult": {
|
|
158
|
+
"import": "./dist/tsResult.js",
|
|
159
|
+
"types": "./dist/tsResult.d.ts",
|
|
160
|
+
"require": "./dist/tsResult.cjs"
|
|
161
|
+
},
|
|
172
162
|
"./typingFnUtils": {
|
|
173
163
|
"import": "./dist/typingFnUtils.js",
|
|
174
164
|
"types": "./dist/typingFnUtils.d.ts",
|
|
@@ -253,11 +243,8 @@
|
|
|
253
243
|
"exhaustiveMatch": [
|
|
254
244
|
"./dist/exhaustiveMatch.d.ts"
|
|
255
245
|
],
|
|
256
|
-
"
|
|
257
|
-
"./dist/
|
|
258
|
-
],
|
|
259
|
-
"internalUtils": [
|
|
260
|
-
"./dist/internalUtils.d.ts"
|
|
246
|
+
"getValueStableKey": [
|
|
247
|
+
"./dist/getValueStableKey.d.ts"
|
|
261
248
|
],
|
|
262
249
|
"interpolate": [
|
|
263
250
|
"./dist/interpolate.d.ts"
|
|
@@ -265,9 +252,6 @@
|
|
|
265
252
|
"levenshtein": [
|
|
266
253
|
"./dist/levenshtein.d.ts"
|
|
267
254
|
],
|
|
268
|
-
"main": [
|
|
269
|
-
"./dist/main.d.ts"
|
|
270
|
-
],
|
|
271
255
|
"mathUtils": [
|
|
272
256
|
"./dist/mathUtils.d.ts"
|
|
273
257
|
],
|
|
@@ -283,9 +267,6 @@
|
|
|
283
267
|
"retryOnError": [
|
|
284
268
|
"./dist/retryOnError.d.ts"
|
|
285
269
|
],
|
|
286
|
-
"rsResult": [
|
|
287
|
-
"./dist/rsResult.d.ts"
|
|
288
|
-
],
|
|
289
270
|
"runShellCmd": [
|
|
290
271
|
"./dist/runShellCmd.d.ts"
|
|
291
272
|
],
|
|
@@ -307,6 +288,9 @@
|
|
|
307
288
|
"time": [
|
|
308
289
|
"./dist/time.d.ts"
|
|
309
290
|
],
|
|
291
|
+
"tsResult": [
|
|
292
|
+
"./dist/tsResult.d.ts"
|
|
293
|
+
],
|
|
310
294
|
"typingFnUtils": [
|
|
311
295
|
"./dist/typingFnUtils.d.ts"
|
|
312
296
|
],
|
package/dist/chunk-GBFS2I67.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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 isNumeric(value) ? Number(value) : null;
|
|
8
|
-
}
|
|
9
|
-
function isNumeric(num) {
|
|
10
|
-
const str = String(num);
|
|
11
|
-
return !isNaN(str) && !isNaN(parseFloat(str));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
castToString,
|
|
16
|
-
castToNumber
|
|
17
|
-
};
|
package/dist/getObjStableKey.cjs
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
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/getObjStableKey.ts
|
|
21
|
-
var getObjStableKey_exports = {};
|
|
22
|
-
__export(getObjStableKey_exports, {
|
|
23
|
-
getObjStableKey: () => getObjStableKey
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(getObjStableKey_exports);
|
|
26
|
-
|
|
27
|
-
// src/arrayUtils.ts
|
|
28
|
-
function filterAndMap(array, mapFilter) {
|
|
29
|
-
const result = [];
|
|
30
|
-
let i = -1;
|
|
31
|
-
for (const item of array) {
|
|
32
|
-
i += 1;
|
|
33
|
-
const filterResult = mapFilter(item, i);
|
|
34
|
-
if (filterResult !== false) {
|
|
35
|
-
result.push(filterResult);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// src/assertions.ts
|
|
42
|
-
function isObject(value) {
|
|
43
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/getObjStableKey.ts
|
|
47
|
-
function getObjStableKey(input, maxDepth = 3) {
|
|
48
|
-
if (typeof input === "string") return String(input);
|
|
49
|
-
if (!input || typeof input !== "object") return `#$${input}$#`;
|
|
50
|
-
return JSON.stringify(sortValues(input, maxDepth, 0));
|
|
51
|
-
}
|
|
52
|
-
function sortValues(input, maxDepth, depth) {
|
|
53
|
-
if (depth >= maxDepth) return input;
|
|
54
|
-
if (Array.isArray(input)) {
|
|
55
|
-
return input.map((v) => sortValues(v, maxDepth, depth + 1));
|
|
56
|
-
}
|
|
57
|
-
if (isObject(input)) {
|
|
58
|
-
return orderedProps(input, (v) => sortValues(v, maxDepth, depth + 1));
|
|
59
|
-
}
|
|
60
|
-
return input;
|
|
61
|
-
}
|
|
62
|
-
var emptyObject = {};
|
|
63
|
-
function orderedProps(obj, mapValue) {
|
|
64
|
-
const keys = Object.keys(obj);
|
|
65
|
-
if (keys.length === 0) return emptyObject;
|
|
66
|
-
if (keys.length === 1) {
|
|
67
|
-
const value = obj[keys[0]];
|
|
68
|
-
if (value === void 0) return emptyObject;
|
|
69
|
-
return { [keys[0]]: mapValue(value) };
|
|
70
|
-
}
|
|
71
|
-
const mappedValues = filterAndMap(keys.sort(), (k) => {
|
|
72
|
-
const value = obj[k];
|
|
73
|
-
if (value === void 0) return false;
|
|
74
|
-
return { [k]: mapValue(value) };
|
|
75
|
-
});
|
|
76
|
-
if (mappedValues.length === 0) return emptyObject;
|
|
77
|
-
if (mappedValues.length === 1) return mappedValues[0];
|
|
78
|
-
return mappedValues;
|
|
79
|
-
}
|
|
80
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
-
0 && (module.exports = {
|
|
82
|
-
getObjStableKey
|
|
83
|
-
});
|
package/dist/getObjStableKey.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
filterAndMap
|
|
3
|
-
} from "./chunk-QMFZE2VO.js";
|
|
4
|
-
import {
|
|
5
|
-
isObject
|
|
6
|
-
} from "./chunk-4UGSP3L3.js";
|
|
7
|
-
|
|
8
|
-
// src/getObjStableKey.ts
|
|
9
|
-
function getObjStableKey(input, maxDepth = 3) {
|
|
10
|
-
if (typeof input === "string") return String(input);
|
|
11
|
-
if (!input || typeof input !== "object") return `#$${input}$#`;
|
|
12
|
-
return JSON.stringify(sortValues(input, maxDepth, 0));
|
|
13
|
-
}
|
|
14
|
-
function sortValues(input, maxDepth, depth) {
|
|
15
|
-
if (depth >= maxDepth) return input;
|
|
16
|
-
if (Array.isArray(input)) {
|
|
17
|
-
return input.map((v) => sortValues(v, maxDepth, depth + 1));
|
|
18
|
-
}
|
|
19
|
-
if (isObject(input)) {
|
|
20
|
-
return orderedProps(input, (v) => sortValues(v, maxDepth, depth + 1));
|
|
21
|
-
}
|
|
22
|
-
return input;
|
|
23
|
-
}
|
|
24
|
-
var emptyObject = {};
|
|
25
|
-
function orderedProps(obj, mapValue) {
|
|
26
|
-
const keys = Object.keys(obj);
|
|
27
|
-
if (keys.length === 0) return emptyObject;
|
|
28
|
-
if (keys.length === 1) {
|
|
29
|
-
const value = obj[keys[0]];
|
|
30
|
-
if (value === void 0) return emptyObject;
|
|
31
|
-
return { [keys[0]]: mapValue(value) };
|
|
32
|
-
}
|
|
33
|
-
const mappedValues = filterAndMap(keys.sort(), (k) => {
|
|
34
|
-
const value = obj[k];
|
|
35
|
-
if (value === void 0) return false;
|
|
36
|
-
return { [k]: mapValue(value) };
|
|
37
|
-
});
|
|
38
|
-
if (mappedValues.length === 0) return emptyObject;
|
|
39
|
-
if (mappedValues.length === 1) return mappedValues[0];
|
|
40
|
-
return mappedValues;
|
|
41
|
-
}
|
|
42
|
-
export {
|
|
43
|
-
getObjStableKey
|
|
44
|
-
};
|
package/dist/rsResult.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Result,
|
|
3
|
-
asyncResultify,
|
|
4
|
-
createTypedResult,
|
|
5
|
-
normalizeError,
|
|
6
|
-
resultify,
|
|
7
|
-
safeJsonStringify,
|
|
8
|
-
unknownToError
|
|
9
|
-
} from "./chunk-KBFP7INB.js";
|
|
10
|
-
import "./chunk-VAAMRG4K.js";
|
|
11
|
-
import "./chunk-4UGSP3L3.js";
|
|
12
|
-
export {
|
|
13
|
-
Result,
|
|
14
|
-
asyncResultify,
|
|
15
|
-
createTypedResult,
|
|
16
|
-
normalizeError,
|
|
17
|
-
resultify,
|
|
18
|
-
safeJsonStringify,
|
|
19
|
-
unknownToError
|
|
20
|
-
};
|