@ls-stack/utils 3.12.2 → 3.13.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/lib/asyncQueue.cjs +3 -1
- package/lib/asyncQueue.js +3 -1
- package/lib/chunk-U44EKR2F.js +56 -0
- package/lib/getCompositeKey.cjs +83 -0
- package/lib/getCompositeKey.d.cts +10 -0
- package/lib/getCompositeKey.d.ts +10 -0
- package/lib/getCompositeKey.js +7 -0
- package/lib/getValueStableKey.cjs +5 -2
- package/lib/getValueStableKey.d.cts +5 -1
- package/lib/getValueStableKey.d.ts +5 -1
- package/lib/getValueStableKey.js +4 -49
- package/lib/objUtils.d.cts +1 -0
- package/lib/objUtils.d.ts +1 -0
- package/lib/saferTyping.d.cts +11 -1
- package/lib/saferTyping.d.ts +11 -1
- package/package.json +5 -1
package/lib/asyncQueue.cjs
CHANGED
|
@@ -143,7 +143,9 @@ var AsyncQueue = class {
|
|
|
143
143
|
if (signal) {
|
|
144
144
|
const error = signal.reason instanceof Error ? signal.reason : new DOMException("This operation was aborted", "AbortError");
|
|
145
145
|
abortListener = () => {
|
|
146
|
-
|
|
146
|
+
setTimeout(() => {
|
|
147
|
+
reject(error);
|
|
148
|
+
}, 0);
|
|
147
149
|
};
|
|
148
150
|
signal.addEventListener("abort", abortListener, { once: true });
|
|
149
151
|
}
|
package/lib/asyncQueue.js
CHANGED
|
@@ -114,7 +114,9 @@ var AsyncQueue = class {
|
|
|
114
114
|
if (signal) {
|
|
115
115
|
const error = signal.reason instanceof Error ? signal.reason : new DOMException("This operation was aborted", "AbortError");
|
|
116
116
|
abortListener = () => {
|
|
117
|
-
|
|
117
|
+
setTimeout(() => {
|
|
118
|
+
reject(error);
|
|
119
|
+
}, 0);
|
|
118
120
|
};
|
|
119
121
|
signal.addEventListener("abort", abortListener, { once: true });
|
|
120
122
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isObject
|
|
3
|
+
} from "./chunk-3XCS7FVO.js";
|
|
4
|
+
|
|
5
|
+
// src/getCompositeKey.ts
|
|
6
|
+
function getCompositeKey(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
|
+
|
|
54
|
+
export {
|
|
55
|
+
getCompositeKey
|
|
56
|
+
};
|
|
@@ -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/getCompositeKey.ts
|
|
21
|
+
var getCompositeKey_exports = {};
|
|
22
|
+
__export(getCompositeKey_exports, {
|
|
23
|
+
getCompositeKey: () => getCompositeKey
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(getCompositeKey_exports);
|
|
26
|
+
|
|
27
|
+
// src/assertions.ts
|
|
28
|
+
function isObject(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/getCompositeKey.ts
|
|
33
|
+
function getCompositeKey(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
|
+
getCompositeKey
|
|
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 getCompositeKey(input: unknown, maxSortingDepth?: number): string;
|
|
9
|
+
|
|
10
|
+
export { getCompositeKey };
|
|
@@ -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 getCompositeKey(input: unknown, maxSortingDepth?: number): string;
|
|
9
|
+
|
|
10
|
+
export { getCompositeKey };
|
|
@@ -29,8 +29,8 @@ function isObject(value) {
|
|
|
29
29
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
// src/
|
|
33
|
-
function
|
|
32
|
+
// src/getCompositeKey.ts
|
|
33
|
+
function getCompositeKey(input, maxSortingDepth = 3) {
|
|
34
34
|
if (typeof input === "string") return `"${input}`;
|
|
35
35
|
if (!input || typeof input !== "object") return `$${input}`;
|
|
36
36
|
return stringifyCompact(input, maxSortingDepth, 0, /* @__PURE__ */ new WeakSet());
|
|
@@ -77,6 +77,9 @@ function stringifyCompact(input, maxSortingDepth, depth, refs) {
|
|
|
77
77
|
}
|
|
78
78
|
return result;
|
|
79
79
|
}
|
|
80
|
+
|
|
81
|
+
// src/getValueStableKey.ts
|
|
82
|
+
var getValueStableKey = getCompositeKey;
|
|
80
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
84
|
0 && (module.exports = {
|
|
82
85
|
getValueStableKey
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { getCompositeKey } from './getCompositeKey.cjs';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Returns a stable key for the input value.
|
|
3
5
|
*
|
|
4
6
|
* @param input - The value to get a stable key for.
|
|
5
7
|
* @param maxSortingDepth - The maximum depth to sort the input value. Default is 3.
|
|
6
8
|
* @returns A stable key for the input value.
|
|
9
|
+
*
|
|
10
|
+
* @deprecated Use `getCompositeKey` from `@ls-stack/utils/getCompositeKey` instead.
|
|
7
11
|
*/
|
|
8
|
-
declare
|
|
12
|
+
declare const getValueStableKey: typeof getCompositeKey;
|
|
9
13
|
|
|
10
14
|
export { getValueStableKey };
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { getCompositeKey } from './getCompositeKey.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Returns a stable key for the input value.
|
|
3
5
|
*
|
|
4
6
|
* @param input - The value to get a stable key for.
|
|
5
7
|
* @param maxSortingDepth - The maximum depth to sort the input value. Default is 3.
|
|
6
8
|
* @returns A stable key for the input value.
|
|
9
|
+
*
|
|
10
|
+
* @deprecated Use `getCompositeKey` from `@ls-stack/utils/getCompositeKey` instead.
|
|
7
11
|
*/
|
|
8
|
-
declare
|
|
12
|
+
declare const getValueStableKey: typeof getCompositeKey;
|
|
9
13
|
|
|
10
14
|
export { getValueStableKey };
|
package/lib/getValueStableKey.js
CHANGED
|
@@ -1,55 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
getCompositeKey
|
|
3
|
+
} from "./chunk-U44EKR2F.js";
|
|
4
|
+
import "./chunk-3XCS7FVO.js";
|
|
4
5
|
|
|
5
6
|
// src/getValueStableKey.ts
|
|
6
|
-
|
|
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
|
-
}
|
|
7
|
+
var getValueStableKey = getCompositeKey;
|
|
53
8
|
export {
|
|
54
9
|
getValueStableKey
|
|
55
10
|
};
|
package/lib/objUtils.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @deprecated use typedObjectEntries from @ls-stack/utils/typingFnUtils instead */
|
|
1
2
|
declare function objectTypedEntries<T extends Record<string, unknown>>(obj: T): [Extract<keyof T, string>, T[keyof T]][];
|
|
2
3
|
declare function pick<T, K extends keyof T>(obj: T | undefined, keys: K[], rename?: Partial<Record<K, string>>): Record<string, unknown>;
|
|
3
4
|
declare function mapArrayToObject<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
|
package/lib/objUtils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @deprecated use typedObjectEntries from @ls-stack/utils/typingFnUtils instead */
|
|
1
2
|
declare function objectTypedEntries<T extends Record<string, unknown>>(obj: T): [Extract<keyof T, string>, T[keyof T]][];
|
|
2
3
|
declare function pick<T, K extends keyof T>(obj: T | undefined, keys: K[], rename?: Partial<Record<K, string>>): Record<string, unknown>;
|
|
3
4
|
declare function mapArrayToObject<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
|
package/lib/saferTyping.d.cts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/** Use this only when you have 100% of certainty that this will not break the types */
|
|
2
2
|
type __LEGIT_ANY__ = any;
|
|
3
|
+
type __LEGIT_ANY_FUNCTION__ = (...params: any) => __LEGIT_ANY__;
|
|
4
|
+
/**
|
|
5
|
+
* An empty object type, equivalent to `{}` but with safer typing
|
|
6
|
+
*/
|
|
7
|
+
type EmptyObject = Record<string, never>;
|
|
3
8
|
/**
|
|
4
9
|
* Cast a value to `any` type. Use this when you have legit usage of `any` casting.
|
|
5
10
|
*
|
|
@@ -23,5 +28,10 @@ declare function __REFINE_CAST__<T>(value: T): <R extends T>() => R;
|
|
|
23
28
|
declare function __FIX_THIS_CASTING__<T>(value: unknown): T;
|
|
24
29
|
type __FIX_THIS_TYPING__ = any;
|
|
25
30
|
declare function __FIX_THIS_TYPING__(value: unknown): __LEGIT_ANY__;
|
|
31
|
+
/**
|
|
32
|
+
* Any type that is not a primitive (number, string, boolean, null, undefined, symbol, bigint, ...)
|
|
33
|
+
* Equivalent to `object` type
|
|
34
|
+
*/
|
|
35
|
+
type AnyNonPrimitiveValue = object;
|
|
26
36
|
|
|
27
|
-
export { __FIX_THIS_CASTING__, __FIX_THIS_TYPING__, __LEGIT_ANY_CAST__, type __LEGIT_ANY__, __LEGIT_CAST__, __REFINE_CAST__ };
|
|
37
|
+
export { type AnyNonPrimitiveValue, type EmptyObject, __FIX_THIS_CASTING__, __FIX_THIS_TYPING__, __LEGIT_ANY_CAST__, type __LEGIT_ANY_FUNCTION__, type __LEGIT_ANY__, __LEGIT_CAST__, __REFINE_CAST__ };
|
package/lib/saferTyping.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/** Use this only when you have 100% of certainty that this will not break the types */
|
|
2
2
|
type __LEGIT_ANY__ = any;
|
|
3
|
+
type __LEGIT_ANY_FUNCTION__ = (...params: any) => __LEGIT_ANY__;
|
|
4
|
+
/**
|
|
5
|
+
* An empty object type, equivalent to `{}` but with safer typing
|
|
6
|
+
*/
|
|
7
|
+
type EmptyObject = Record<string, never>;
|
|
3
8
|
/**
|
|
4
9
|
* Cast a value to `any` type. Use this when you have legit usage of `any` casting.
|
|
5
10
|
*
|
|
@@ -23,5 +28,10 @@ declare function __REFINE_CAST__<T>(value: T): <R extends T>() => R;
|
|
|
23
28
|
declare function __FIX_THIS_CASTING__<T>(value: unknown): T;
|
|
24
29
|
type __FIX_THIS_TYPING__ = any;
|
|
25
30
|
declare function __FIX_THIS_TYPING__(value: unknown): __LEGIT_ANY__;
|
|
31
|
+
/**
|
|
32
|
+
* Any type that is not a primitive (number, string, boolean, null, undefined, symbol, bigint, ...)
|
|
33
|
+
* Equivalent to `object` type
|
|
34
|
+
*/
|
|
35
|
+
type AnyNonPrimitiveValue = object;
|
|
26
36
|
|
|
27
|
-
export { __FIX_THIS_CASTING__, __FIX_THIS_TYPING__, __LEGIT_ANY_CAST__, type __LEGIT_ANY__, __LEGIT_CAST__, __REFINE_CAST__ };
|
|
37
|
+
export { type AnyNonPrimitiveValue, type EmptyObject, __FIX_THIS_CASTING__, __FIX_THIS_TYPING__, __LEGIT_ANY_CAST__, type __LEGIT_ANY_FUNCTION__, type __LEGIT_ANY__, __LEGIT_CAST__, __REFINE_CAST__ };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-stack/utils",
|
|
3
3
|
"description": "Typescript utils",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.13.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib"
|
|
@@ -74,6 +74,10 @@
|
|
|
74
74
|
"import": "./lib/exhaustiveMatch.js",
|
|
75
75
|
"require": "./lib/exhaustiveMatch.cjs"
|
|
76
76
|
},
|
|
77
|
+
"./getCompositeKey": {
|
|
78
|
+
"import": "./lib/getCompositeKey.js",
|
|
79
|
+
"require": "./lib/getCompositeKey.cjs"
|
|
80
|
+
},
|
|
77
81
|
"./getValueStableKey": {
|
|
78
82
|
"import": "./lib/getValueStableKey.js",
|
|
79
83
|
"require": "./lib/getValueStableKey.cjs"
|