@ls-stack/utils 3.18.0 → 3.19.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/README.md +1 -15
- package/docs/README.md +72 -0
- package/docs/_media/modules.md +52 -0
- package/docs/arrayUtils/-internal-.md +17 -0
- package/docs/arrayUtils/README.md +423 -0
- package/docs/assertions/-internal-.md +63 -0
- package/docs/assertions/README.md +565 -0
- package/docs/asyncQueue/-internal-.md +815 -0
- package/docs/asyncQueue/README.md +75 -0
- package/docs/awaitDebounce.md +66 -0
- package/docs/cache/-internal-.md +168 -0
- package/docs/cache/README.md +360 -0
- package/docs/castValues.md +47 -0
- package/docs/concurrentCalls/-internal-.md +416 -0
- package/docs/concurrentCalls/README.md +77 -0
- package/docs/consoleFmt.md +91 -0
- package/docs/conversions.md +27 -0
- package/docs/createThrottleController/-internal-.md +73 -0
- package/docs/createThrottleController/README.md +31 -0
- package/docs/debounce.md +188 -0
- package/docs/dedent.md +117 -0
- package/docs/deepEqual.md +94 -0
- package/docs/enhancedMap.md +358 -0
- package/docs/exhaustiveMatch/-internal-.md +39 -0
- package/docs/exhaustiveMatch/README.md +146 -0
- package/docs/getAutoIncrementId.md +93 -0
- package/docs/getCompositeKey.md +39 -0
- package/docs/getValueStableKey.md +57 -0
- package/docs/hash.md +31 -0
- package/docs/interpolate/-internal-.md +61 -0
- package/docs/interpolate/README.md +62 -0
- package/docs/levenshtein.md +93 -0
- package/docs/main.md +21 -0
- package/docs/mathUtils.md +137 -0
- package/docs/modules.md +52 -0
- package/docs/objUtils.md +237 -0
- package/docs/parallelAsyncCalls/-internal-.md +347 -0
- package/docs/parallelAsyncCalls/README.md +45 -0
- package/docs/promiseUtils/-internal-.md +69 -0
- package/docs/promiseUtils/README.md +31 -0
- package/docs/retryOnError.md +67 -0
- package/docs/runShellCmd/-internal-.md +111 -0
- package/docs/runShellCmd/README.md +201 -0
- package/docs/safeJson.md +51 -0
- package/docs/saferTyping.md +228 -0
- package/docs/serializeXML.md +100 -0
- package/docs/shallowEqual.md +33 -0
- package/docs/sleep.md +27 -0
- package/docs/stringUtils/-internal-.md +17 -0
- package/docs/stringUtils/README.md +166 -0
- package/docs/testUtils.md +315 -0
- package/docs/throttle/-internal-.md +47 -0
- package/docs/throttle/README.md +178 -0
- package/docs/time.md +274 -0
- package/docs/timers.md +256 -0
- package/docs/tsResult/-internal-.md +327 -0
- package/docs/tsResult/README.md +696 -0
- package/docs/typeGuards.md +399 -0
- package/docs/typingFnUtils/-internal-.md +27 -0
- package/docs/typingFnUtils/README.md +293 -0
- package/docs/typingTestUtils.md +172 -0
- package/docs/typingUtils.md +111 -0
- package/docs/yamlStringify.md +45 -0
- package/lib/arrayUtils.js +3 -3
- package/lib/assertions.js +2 -2
- package/lib/awaitDebounce.cjs +106 -0
- package/lib/awaitDebounce.d.cts +38 -0
- package/lib/awaitDebounce.d.ts +38 -0
- package/lib/awaitDebounce.js +28 -0
- package/lib/cache.js +2 -2
- package/lib/{chunk-NH2LCAQS.js → chunk-6FIBVC2P.js} +1 -1
- package/lib/{chunk-GKOTKAIV.js → chunk-7CQPOM5I.js} +1 -1
- package/lib/{chunk-WS4WEVHU.js → chunk-C2SVCIWE.js} +1 -1
- package/lib/{chunk-SSKW673U.js → chunk-JF2MDHOJ.js} +5 -1
- package/lib/chunk-NW5H5EW7.js +100 -0
- package/lib/{chunk-DMW5Q4T2.js → chunk-SRVMMYSW.js} +1 -1
- package/lib/concurrentCalls.js +3 -3
- package/lib/createThrottleController.js +3 -3
- package/lib/debounce.js +4 -95
- package/lib/enhancedMap.js +3 -3
- package/lib/getAutoIncrementId.cjs +44 -0
- package/lib/getAutoIncrementId.d.cts +44 -0
- package/lib/getAutoIncrementId.d.ts +44 -0
- package/lib/getAutoIncrementId.js +18 -0
- package/lib/getCompositeKey.js +3 -3
- package/lib/getValueStableKey.js +3 -3
- package/lib/interpolate.js +2 -2
- package/lib/parallelAsyncCalls.js +2 -2
- package/lib/runShellCmd.d.cts +50 -0
- package/lib/runShellCmd.d.ts +50 -0
- package/lib/serializeXML.cjs +7 -2
- package/lib/serializeXML.d.cts +1 -1
- package/lib/serializeXML.d.ts +1 -1
- package/lib/serializeXML.js +7 -5
- package/lib/testUtils.js +3 -3
- package/lib/throttle.cjs +250 -0
- package/lib/throttle.d.cts +89 -0
- package/lib/throttle.d.ts +89 -0
- package/lib/throttle.js +38 -0
- package/lib/tsResult.js +2 -2
- package/lib/typeGuards.cjs +7 -2
- package/lib/typeGuards.d.cts +2 -1
- package/lib/typeGuards.d.ts +2 -1
- package/lib/typeGuards.js +5 -3
- package/lib/typingFnUtils.cjs +5 -1
- package/lib/typingFnUtils.d.cts +1 -1
- package/lib/typingFnUtils.d.ts +1 -1
- package/lib/typingFnUtils.js +5 -1
- package/lib/yamlStringify.js +5 -5
- package/package.json +22 -12
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
[**@ls-stack/utils**](README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](modules.md) / typingTestUtils
|
|
6
|
+
|
|
7
|
+
# typingTestUtils
|
|
8
|
+
|
|
9
|
+
## Type Aliases
|
|
10
|
+
|
|
11
|
+
### TestTypeIsEqual\<X, Y\>
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
type TestTypeIsEqual<X, Y> = <T>() => T extends X ? 1 : 2 extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/typingTestUtils.ts:1](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingTestUtils.ts#L1)
|
|
18
|
+
|
|
19
|
+
#### Type Parameters
|
|
20
|
+
|
|
21
|
+
##### X
|
|
22
|
+
|
|
23
|
+
`X`
|
|
24
|
+
|
|
25
|
+
##### Y
|
|
26
|
+
|
|
27
|
+
`Y`
|
|
28
|
+
|
|
29
|
+
***
|
|
30
|
+
|
|
31
|
+
### TestTypeNotEqual\<X, Y\>
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
type TestTypeNotEqual<X, Y> = true extends TestTypeIsEqual<X, Y> ? false : true;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Defined in: [packages/utils/src/typingTestUtils.ts:4](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingTestUtils.ts#L4)
|
|
38
|
+
|
|
39
|
+
#### Type Parameters
|
|
40
|
+
|
|
41
|
+
##### X
|
|
42
|
+
|
|
43
|
+
`X`
|
|
44
|
+
|
|
45
|
+
##### Y
|
|
46
|
+
|
|
47
|
+
`Y`
|
|
48
|
+
|
|
49
|
+
## Variables
|
|
50
|
+
|
|
51
|
+
### typingTest
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const typingTest: object;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Defined in: [packages/utils/src/typingTestUtils.ts:48](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingTestUtils.ts#L48)
|
|
58
|
+
|
|
59
|
+
#### Type declaration
|
|
60
|
+
|
|
61
|
+
##### describe()
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
describe: (title, func) => void;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
###### Parameters
|
|
68
|
+
|
|
69
|
+
###### title
|
|
70
|
+
|
|
71
|
+
`string`
|
|
72
|
+
|
|
73
|
+
###### func
|
|
74
|
+
|
|
75
|
+
() => `any`
|
|
76
|
+
|
|
77
|
+
###### Returns
|
|
78
|
+
|
|
79
|
+
`void`
|
|
80
|
+
|
|
81
|
+
##### expectType()
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
expectType: <T>() => T;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Helper function for type testing that ensures a type extends `true`.
|
|
88
|
+
Used in combination with `TestTypeIsEqual` to verify type equality at compile time.
|
|
89
|
+
|
|
90
|
+
###### Type Parameters
|
|
91
|
+
|
|
92
|
+
###### T
|
|
93
|
+
|
|
94
|
+
`T` *extends* `true`
|
|
95
|
+
|
|
96
|
+
Type that must extend `true`
|
|
97
|
+
|
|
98
|
+
###### Returns
|
|
99
|
+
|
|
100
|
+
`T`
|
|
101
|
+
|
|
102
|
+
An empty object cast to type T
|
|
103
|
+
|
|
104
|
+
###### Example
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
expectType<TestTypeIsEqual<string, string>>(); // OK
|
|
108
|
+
expectType<TestTypeIsEqual<string, number>>(); // Type error
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
##### expectTypesAre()
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
expectTypesAre: <X, Y>(result) => void;
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Helper function for type testing that compares two types and expects a specific result.
|
|
118
|
+
This function allows for more explicit type equality assertions with a descriptive result.
|
|
119
|
+
|
|
120
|
+
###### Type Parameters
|
|
121
|
+
|
|
122
|
+
###### X
|
|
123
|
+
|
|
124
|
+
`X`
|
|
125
|
+
|
|
126
|
+
First type to compare
|
|
127
|
+
|
|
128
|
+
###### Y
|
|
129
|
+
|
|
130
|
+
`Y`
|
|
131
|
+
|
|
132
|
+
Second type to compare
|
|
133
|
+
|
|
134
|
+
###### Parameters
|
|
135
|
+
|
|
136
|
+
###### result
|
|
137
|
+
|
|
138
|
+
[`TestTypeIsEqual`](#testtypeisequal)\<`X`, `Y`\> *extends* `true` ? `"equal"` : `"notEqual"`
|
|
139
|
+
|
|
140
|
+
Expected comparison result: 'equal' if types are equal, 'notEqual' if they differ
|
|
141
|
+
|
|
142
|
+
###### Returns
|
|
143
|
+
|
|
144
|
+
`void`
|
|
145
|
+
|
|
146
|
+
###### Example
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
expectTypesAre<string, string>('equal'); // OK
|
|
150
|
+
expectTypesAre<string, number>('notEqual'); // OK
|
|
151
|
+
expectTypesAre<string, string>('notEqual'); // Type error
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
##### test()
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
test: (title, func) => void;
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
###### Parameters
|
|
161
|
+
|
|
162
|
+
###### title
|
|
163
|
+
|
|
164
|
+
`string`
|
|
165
|
+
|
|
166
|
+
###### func
|
|
167
|
+
|
|
168
|
+
() => `any`
|
|
169
|
+
|
|
170
|
+
###### Returns
|
|
171
|
+
|
|
172
|
+
`void`
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
[**@ls-stack/utils**](README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](modules.md) / typingUtils
|
|
6
|
+
|
|
7
|
+
# typingUtils
|
|
8
|
+
|
|
9
|
+
## Type Aliases
|
|
10
|
+
|
|
11
|
+
### DeepPrettify\<T\>
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
type DeepPrettify<T> = { [K in keyof T]: T[K] extends Record<string, unknown> ? DeepPrettify<T[K]> : T[K] } & object;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/typingUtils.ts:25](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L25)
|
|
18
|
+
|
|
19
|
+
#### Type Parameters
|
|
20
|
+
|
|
21
|
+
##### T
|
|
22
|
+
|
|
23
|
+
`T`
|
|
24
|
+
|
|
25
|
+
***
|
|
26
|
+
|
|
27
|
+
### IsAny\<T\>
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
type IsAny<T> = unknown extends T ? [keyof T] extends [never] ? false : true : false;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Defined in: [packages/utils/src/typingUtils.ts:14](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L14)
|
|
34
|
+
|
|
35
|
+
#### Type Parameters
|
|
36
|
+
|
|
37
|
+
##### T
|
|
38
|
+
|
|
39
|
+
`T`
|
|
40
|
+
|
|
41
|
+
***
|
|
42
|
+
|
|
43
|
+
### NonPartial\<T\>
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
type NonPartial<T> = { [K in keyof Required<T>]: T[K] };
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Defined in: [packages/utils/src/typingUtils.ts:5](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L5)
|
|
50
|
+
|
|
51
|
+
#### Type Parameters
|
|
52
|
+
|
|
53
|
+
##### T
|
|
54
|
+
|
|
55
|
+
`T`
|
|
56
|
+
|
|
57
|
+
***
|
|
58
|
+
|
|
59
|
+
### ObjKeysWithValuesOfType\<Obj, ValueType\>
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
type ObjKeysWithValuesOfType<Obj, ValueType> = { [K in keyof Obj]: Obj[K] extends ValueType ? K : never }[keyof Obj];
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Defined in: [packages/utils/src/typingUtils.ts:7](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L7)
|
|
66
|
+
|
|
67
|
+
#### Type Parameters
|
|
68
|
+
|
|
69
|
+
##### Obj
|
|
70
|
+
|
|
71
|
+
`Obj` *extends* `Record`\<`PropertyKey`, `unknown`\>
|
|
72
|
+
|
|
73
|
+
##### ValueType
|
|
74
|
+
|
|
75
|
+
`ValueType`
|
|
76
|
+
|
|
77
|
+
***
|
|
78
|
+
|
|
79
|
+
### PartialRecord\<K, T\>
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
type PartialRecord<K, T> = { [P in K]?: T };
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Defined in: [packages/utils/src/typingUtils.ts:1](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L1)
|
|
86
|
+
|
|
87
|
+
#### Type Parameters
|
|
88
|
+
|
|
89
|
+
##### K
|
|
90
|
+
|
|
91
|
+
`K` *extends* keyof `any`
|
|
92
|
+
|
|
93
|
+
##### T
|
|
94
|
+
|
|
95
|
+
`T`
|
|
96
|
+
|
|
97
|
+
***
|
|
98
|
+
|
|
99
|
+
### Prettify\<T\>
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
type Prettify<T> = { [P in keyof T]: T[P] } & object;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Defined in: [packages/utils/src/typingUtils.ts:21](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L21)
|
|
106
|
+
|
|
107
|
+
#### Type Parameters
|
|
108
|
+
|
|
109
|
+
##### T
|
|
110
|
+
|
|
111
|
+
`T` *extends* `Record`\<`string`, `unknown`\>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[**@ls-stack/utils**](README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](modules.md) / yamlStringify
|
|
6
|
+
|
|
7
|
+
# yamlStringify
|
|
8
|
+
|
|
9
|
+
## Functions
|
|
10
|
+
|
|
11
|
+
### yamlStringify()
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
function yamlStringify(obj, __namedParameters): string;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/yamlStringify.ts:5](https://github.com/lucasols/utils/blob/main/packages/utils/src/yamlStringify.ts#L5)
|
|
18
|
+
|
|
19
|
+
#### Parameters
|
|
20
|
+
|
|
21
|
+
##### obj
|
|
22
|
+
|
|
23
|
+
`unknown`
|
|
24
|
+
|
|
25
|
+
##### \_\_namedParameters
|
|
26
|
+
|
|
27
|
+
###### addRootObjSpaces?
|
|
28
|
+
|
|
29
|
+
`false` \| `"beforeAndAfter"` \| `"before"` \| `"after"` = `'beforeAndAfter'`
|
|
30
|
+
|
|
31
|
+
###### maxDepth?
|
|
32
|
+
|
|
33
|
+
`number` = `50`
|
|
34
|
+
|
|
35
|
+
###### maxLineLength?
|
|
36
|
+
|
|
37
|
+
`number` = `100`
|
|
38
|
+
|
|
39
|
+
###### showUndefined?
|
|
40
|
+
|
|
41
|
+
`boolean`
|
|
42
|
+
|
|
43
|
+
#### Returns
|
|
44
|
+
|
|
45
|
+
`string`
|
package/lib/arrayUtils.js
CHANGED
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
rejectDuplicates,
|
|
11
11
|
sortBy,
|
|
12
12
|
truncateArray
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-SRVMMYSW.js";
|
|
14
|
+
import "./chunk-C2SVCIWE.js";
|
|
15
|
+
import "./chunk-JF2MDHOJ.js";
|
|
16
16
|
export {
|
|
17
17
|
arrayWithPrev,
|
|
18
18
|
arrayWithPrevAndIndex,
|
package/lib/assertions.js
CHANGED
|
@@ -0,0 +1,106 @@
|
|
|
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/awaitDebounce.ts
|
|
21
|
+
var awaitDebounce_exports = {};
|
|
22
|
+
__export(awaitDebounce_exports, {
|
|
23
|
+
awaitDebounce: () => awaitDebounce
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(awaitDebounce_exports);
|
|
26
|
+
|
|
27
|
+
// src/typeGuards.ts
|
|
28
|
+
function isObject(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/assertions.ts
|
|
33
|
+
var isObject2 = isObject;
|
|
34
|
+
|
|
35
|
+
// src/getCompositeKey.ts
|
|
36
|
+
function getCompositeKey(input, maxSortingDepth = 3) {
|
|
37
|
+
if (typeof input === "string") return `"${input}`;
|
|
38
|
+
if (!input || typeof input !== "object") return `$${input}`;
|
|
39
|
+
return stringifyCompact(input, maxSortingDepth, 0, /* @__PURE__ */ new WeakSet());
|
|
40
|
+
}
|
|
41
|
+
function stringifyCompact(input, maxSortingDepth, depth, refs) {
|
|
42
|
+
const isJsObj = input && typeof input === "object";
|
|
43
|
+
if (isJsObj) {
|
|
44
|
+
if (refs.has(input)) {
|
|
45
|
+
throw new Error("Circular reference detected");
|
|
46
|
+
}
|
|
47
|
+
refs.add(input);
|
|
48
|
+
}
|
|
49
|
+
let result;
|
|
50
|
+
if (Array.isArray(input)) {
|
|
51
|
+
result = "[";
|
|
52
|
+
for (const v of input) {
|
|
53
|
+
if (result.length > 1) result += ",";
|
|
54
|
+
result += stringifyCompact(v, maxSortingDepth, depth + 1, refs);
|
|
55
|
+
}
|
|
56
|
+
result += "]";
|
|
57
|
+
} else if (isObject2(input)) {
|
|
58
|
+
let entries = Object.entries(input);
|
|
59
|
+
if (entries.length === 0) {
|
|
60
|
+
result = "{}";
|
|
61
|
+
} else {
|
|
62
|
+
if (depth < maxSortingDepth) {
|
|
63
|
+
entries = entries.sort(
|
|
64
|
+
([a], [b]) => a < b ? -1 : a > b ? 1 : 0
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
result = "{";
|
|
68
|
+
for (const [k, v] of entries) {
|
|
69
|
+
if (v === void 0) continue;
|
|
70
|
+
if (result.length > 1) result += ",";
|
|
71
|
+
result += `${k}:${stringifyCompact(v, maxSortingDepth, depth + 1, refs)}`;
|
|
72
|
+
}
|
|
73
|
+
result += "}";
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
result = JSON.stringify(input);
|
|
77
|
+
}
|
|
78
|
+
if (isJsObj) {
|
|
79
|
+
refs.delete(input);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/awaitDebounce.ts
|
|
85
|
+
var resolvers = {};
|
|
86
|
+
var debouncers = {};
|
|
87
|
+
async function awaitDebounce({
|
|
88
|
+
callId: _callId,
|
|
89
|
+
debounce
|
|
90
|
+
}) {
|
|
91
|
+
const callId = getCompositeKey(_callId);
|
|
92
|
+
if (debouncers[callId]) clearTimeout(debouncers[callId]);
|
|
93
|
+
debouncers[callId] = globalThis.setTimeout(() => {
|
|
94
|
+
const resolve = resolvers[callId];
|
|
95
|
+
resolvers[callId] = void 0;
|
|
96
|
+
resolve?.("continue");
|
|
97
|
+
}, debounce);
|
|
98
|
+
if (resolvers[callId]) resolvers[callId]("skip");
|
|
99
|
+
return new Promise((resolve) => {
|
|
100
|
+
resolvers[callId] = resolve;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
awaitDebounce
|
|
106
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __LEGIT_ANY__ } from './saferTyping.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an awaitable debounce mechanism that allows you to debounce async operations.
|
|
5
|
+
* When called multiple times with the same `callId`, only the last call will resolve with 'continue',
|
|
6
|
+
* while all previous calls resolve with 'skip'.
|
|
7
|
+
*
|
|
8
|
+
* This is useful for debouncing API calls, search operations, or any async work where you want
|
|
9
|
+
* to ensure only the most recent request is processed.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Configuration object
|
|
12
|
+
* @param options.callId - Unique identifier for the debounce group. Calls with the same ID are debounced together
|
|
13
|
+
* @param options.debounce - Debounce delay in milliseconds
|
|
14
|
+
* @returns Promise that resolves to 'continue' if this call should proceed, or 'skip' if it was superseded
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* async function searchUsers(query: string) {
|
|
19
|
+
* const result = await awaitDebounce({ callId: 'search', debounce: 300 });
|
|
20
|
+
* if (result === 'skip') return; // This search was superseded
|
|
21
|
+
*
|
|
22
|
+
* // Only the most recent search will reach here
|
|
23
|
+
* const users = await fetchUsers(query);
|
|
24
|
+
* updateUI(users);
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* // Called rapidly - only the last call will execute
|
|
28
|
+
* searchUsers('a');
|
|
29
|
+
* searchUsers('ab');
|
|
30
|
+
* searchUsers('abc'); // Only this one will continue
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function awaitDebounce({ callId: _callId, debounce, }: {
|
|
34
|
+
callId: __LEGIT_ANY__;
|
|
35
|
+
debounce: number;
|
|
36
|
+
}): Promise<'continue' | 'skip'>;
|
|
37
|
+
|
|
38
|
+
export { awaitDebounce };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __LEGIT_ANY__ } from './saferTyping.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an awaitable debounce mechanism that allows you to debounce async operations.
|
|
5
|
+
* When called multiple times with the same `callId`, only the last call will resolve with 'continue',
|
|
6
|
+
* while all previous calls resolve with 'skip'.
|
|
7
|
+
*
|
|
8
|
+
* This is useful for debouncing API calls, search operations, or any async work where you want
|
|
9
|
+
* to ensure only the most recent request is processed.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Configuration object
|
|
12
|
+
* @param options.callId - Unique identifier for the debounce group. Calls with the same ID are debounced together
|
|
13
|
+
* @param options.debounce - Debounce delay in milliseconds
|
|
14
|
+
* @returns Promise that resolves to 'continue' if this call should proceed, or 'skip' if it was superseded
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* async function searchUsers(query: string) {
|
|
19
|
+
* const result = await awaitDebounce({ callId: 'search', debounce: 300 });
|
|
20
|
+
* if (result === 'skip') return; // This search was superseded
|
|
21
|
+
*
|
|
22
|
+
* // Only the most recent search will reach here
|
|
23
|
+
* const users = await fetchUsers(query);
|
|
24
|
+
* updateUI(users);
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* // Called rapidly - only the last call will execute
|
|
28
|
+
* searchUsers('a');
|
|
29
|
+
* searchUsers('ab');
|
|
30
|
+
* searchUsers('abc'); // Only this one will continue
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function awaitDebounce({ callId: _callId, debounce, }: {
|
|
34
|
+
callId: __LEGIT_ANY__;
|
|
35
|
+
debounce: number;
|
|
36
|
+
}): Promise<'continue' | 'skip'>;
|
|
37
|
+
|
|
38
|
+
export { awaitDebounce };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCompositeKey
|
|
3
|
+
} from "./chunk-6FIBVC2P.js";
|
|
4
|
+
import "./chunk-C2SVCIWE.js";
|
|
5
|
+
import "./chunk-JF2MDHOJ.js";
|
|
6
|
+
|
|
7
|
+
// src/awaitDebounce.ts
|
|
8
|
+
var resolvers = {};
|
|
9
|
+
var debouncers = {};
|
|
10
|
+
async function awaitDebounce({
|
|
11
|
+
callId: _callId,
|
|
12
|
+
debounce
|
|
13
|
+
}) {
|
|
14
|
+
const callId = getCompositeKey(_callId);
|
|
15
|
+
if (debouncers[callId]) clearTimeout(debouncers[callId]);
|
|
16
|
+
debouncers[callId] = globalThis.setTimeout(() => {
|
|
17
|
+
const resolve = resolvers[callId];
|
|
18
|
+
resolvers[callId] = void 0;
|
|
19
|
+
resolve?.("continue");
|
|
20
|
+
}, debounce);
|
|
21
|
+
if (resolvers[callId]) resolvers[callId]("skip");
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
resolvers[callId] = resolve;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
awaitDebounce
|
|
28
|
+
};
|
package/lib/cache.js
CHANGED
|
@@ -5,8 +5,8 @@ import "./chunk-HTCYUMDR.js";
|
|
|
5
5
|
import "./chunk-II4R3VVX.js";
|
|
6
6
|
import {
|
|
7
7
|
isPromise
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-C2SVCIWE.js";
|
|
9
|
+
import "./chunk-JF2MDHOJ.js";
|
|
10
10
|
|
|
11
11
|
// src/cache.ts
|
|
12
12
|
function cachedGetter(getter) {
|
|
@@ -25,6 +25,9 @@ function isNonEmptyArray(value) {
|
|
|
25
25
|
function arrayHasAtLeastXItems(array, minLength) {
|
|
26
26
|
return array.length >= minLength;
|
|
27
27
|
}
|
|
28
|
+
function isTruthy(value) {
|
|
29
|
+
return !!value;
|
|
30
|
+
}
|
|
28
31
|
|
|
29
32
|
export {
|
|
30
33
|
isObject,
|
|
@@ -32,5 +35,6 @@ export {
|
|
|
32
35
|
isPromise,
|
|
33
36
|
isPlainObject,
|
|
34
37
|
isNonEmptyArray,
|
|
35
|
-
arrayHasAtLeastXItems
|
|
38
|
+
arrayHasAtLeastXItems,
|
|
39
|
+
isTruthy
|
|
36
40
|
};
|