@ls-stack/utils 3.17.1 → 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/timers.cjs +93 -0
- package/lib/timers.d.cts +110 -0
- package/lib/timers.d.ts +110 -0
- package/lib/timers.js +65 -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 +26 -12
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
[**@ls-stack/utils**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](../modules.md) / asyncQueue
|
|
6
|
+
|
|
7
|
+
# asyncQueue
|
|
8
|
+
|
|
9
|
+
## Modules
|
|
10
|
+
|
|
11
|
+
- [\<internal\>](-internal-.md)
|
|
12
|
+
|
|
13
|
+
## Functions
|
|
14
|
+
|
|
15
|
+
### createAsyncQueue()
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
function createAsyncQueue<T, E>(options?): AsyncQueue<T, E>;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Defined in: [packages/utils/src/asyncQueue.ts:328](https://github.com/lucasols/utils/blob/main/packages/utils/src/asyncQueue.ts#L328)
|
|
22
|
+
|
|
23
|
+
#### Type Parameters
|
|
24
|
+
|
|
25
|
+
##### T
|
|
26
|
+
|
|
27
|
+
`T`
|
|
28
|
+
|
|
29
|
+
##### E
|
|
30
|
+
|
|
31
|
+
`E` *extends* `ResultValidErrors` = `Error`
|
|
32
|
+
|
|
33
|
+
#### Parameters
|
|
34
|
+
|
|
35
|
+
##### options?
|
|
36
|
+
|
|
37
|
+
[`AsyncQueueOptions`](-internal-.md#asyncqueueoptions)
|
|
38
|
+
|
|
39
|
+
#### Returns
|
|
40
|
+
|
|
41
|
+
[`AsyncQueue`](-internal-.md#asyncqueue)\<`T`, `E`\>
|
|
42
|
+
|
|
43
|
+
***
|
|
44
|
+
|
|
45
|
+
### createAsyncQueueWithMeta()
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
function createAsyncQueueWithMeta<T, I, E>(options?): AsyncQueueWithMeta<T, I, E>;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Defined in: [packages/utils/src/asyncQueue.ts:334](https://github.com/lucasols/utils/blob/main/packages/utils/src/asyncQueue.ts#L334)
|
|
52
|
+
|
|
53
|
+
#### Type Parameters
|
|
54
|
+
|
|
55
|
+
##### T
|
|
56
|
+
|
|
57
|
+
`T`
|
|
58
|
+
|
|
59
|
+
##### I
|
|
60
|
+
|
|
61
|
+
`I`
|
|
62
|
+
|
|
63
|
+
##### E
|
|
64
|
+
|
|
65
|
+
`E` *extends* `ResultValidErrors` = `Error`
|
|
66
|
+
|
|
67
|
+
#### Parameters
|
|
68
|
+
|
|
69
|
+
##### options?
|
|
70
|
+
|
|
71
|
+
[`AsyncQueueOptions`](-internal-.md#asyncqueueoptions)
|
|
72
|
+
|
|
73
|
+
#### Returns
|
|
74
|
+
|
|
75
|
+
[`AsyncQueueWithMeta`](-internal-.md#asyncqueuewithmeta)\<`T`, `I`, `E`\>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[**@ls-stack/utils**](README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](modules.md) / awaitDebounce
|
|
6
|
+
|
|
7
|
+
# awaitDebounce
|
|
8
|
+
|
|
9
|
+
## Functions
|
|
10
|
+
|
|
11
|
+
### awaitDebounce()
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
function awaitDebounce(options): Promise<"skip" | "continue">;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/awaitDebounce.ts:41](https://github.com/lucasols/utils/blob/main/packages/utils/src/awaitDebounce.ts#L41)
|
|
18
|
+
|
|
19
|
+
Creates an awaitable debounce mechanism that allows you to debounce async operations.
|
|
20
|
+
When called multiple times with the same `callId`, only the last call will resolve with 'continue',
|
|
21
|
+
while all previous calls resolve with 'skip'.
|
|
22
|
+
|
|
23
|
+
This is useful for debouncing API calls, search operations, or any async work where you want
|
|
24
|
+
to ensure only the most recent request is processed.
|
|
25
|
+
|
|
26
|
+
#### Parameters
|
|
27
|
+
|
|
28
|
+
##### options
|
|
29
|
+
|
|
30
|
+
Configuration object
|
|
31
|
+
|
|
32
|
+
###### callId
|
|
33
|
+
|
|
34
|
+
`any`
|
|
35
|
+
|
|
36
|
+
Unique identifier for the debounce group. Calls with the same ID are debounced together
|
|
37
|
+
|
|
38
|
+
###### debounce
|
|
39
|
+
|
|
40
|
+
`number`
|
|
41
|
+
|
|
42
|
+
Debounce delay in milliseconds
|
|
43
|
+
|
|
44
|
+
#### Returns
|
|
45
|
+
|
|
46
|
+
`Promise`\<`"skip"` \| `"continue"`\>
|
|
47
|
+
|
|
48
|
+
Promise that resolves to 'continue' if this call should proceed, or 'skip' if it was superseded
|
|
49
|
+
|
|
50
|
+
#### Example
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
async function searchUsers(query: string) {
|
|
54
|
+
const result = await awaitDebounce({ callId: 'search', debounce: 300 });
|
|
55
|
+
if (result === 'skip') return; // This search was superseded
|
|
56
|
+
|
|
57
|
+
// Only the most recent search will reach here
|
|
58
|
+
const users = await fetchUsers(query);
|
|
59
|
+
updateUI(users);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Called rapidly - only the last call will execute
|
|
63
|
+
searchUsers('a');
|
|
64
|
+
searchUsers('ab');
|
|
65
|
+
searchUsers('abc'); // Only this one will continue
|
|
66
|
+
```
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
[**@ls-stack/utils**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](../modules.md) / [cache](README.md) / \<internal\>
|
|
6
|
+
|
|
7
|
+
# \<internal\>
|
|
8
|
+
|
|
9
|
+
## Type Aliases
|
|
10
|
+
|
|
11
|
+
### GetOptions\<T\>
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
type GetOptions<T> = object;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/cache.ts:65](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L65)
|
|
18
|
+
|
|
19
|
+
#### Type Parameters
|
|
20
|
+
|
|
21
|
+
##### T
|
|
22
|
+
|
|
23
|
+
`T`
|
|
24
|
+
|
|
25
|
+
#### Properties
|
|
26
|
+
|
|
27
|
+
##### skipCachingWhen()?
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
optional skipCachingWhen: (value) => boolean;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Defined in: [packages/utils/src/cache.ts:72](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L72)
|
|
34
|
+
|
|
35
|
+
A function that determines whether a value should be rejected from being cached.
|
|
36
|
+
If the function returns true, the value will be returned but not cached.
|
|
37
|
+
|
|
38
|
+
###### Parameters
|
|
39
|
+
|
|
40
|
+
###### value
|
|
41
|
+
|
|
42
|
+
`T`
|
|
43
|
+
|
|
44
|
+
The value to check
|
|
45
|
+
|
|
46
|
+
###### Returns
|
|
47
|
+
|
|
48
|
+
`boolean`
|
|
49
|
+
|
|
50
|
+
true if the value should be rejected, false otherwise
|
|
51
|
+
|
|
52
|
+
***
|
|
53
|
+
|
|
54
|
+
### Options
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
type Options = object;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Defined in: [packages/utils/src/cache.ts:15](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L15)
|
|
61
|
+
|
|
62
|
+
#### Properties
|
|
63
|
+
|
|
64
|
+
##### expirationThrottle?
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
optional expirationThrottle: number;
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Defined in: [packages/utils/src/cache.ts:30](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L30)
|
|
71
|
+
|
|
72
|
+
The throttle for checking expired items in milliseconds.
|
|
73
|
+
|
|
74
|
+
###### Default
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
10_000
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
##### maxCacheSize?
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
optional maxCacheSize: number;
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Defined in: [packages/utils/src/cache.ts:20](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L20)
|
|
87
|
+
|
|
88
|
+
The maximum number of items in the cache.
|
|
89
|
+
|
|
90
|
+
###### Default
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
1000
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
##### maxItemAge?
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
optional maxItemAge: DurationObj;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Defined in: [packages/utils/src/cache.ts:24](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L24)
|
|
103
|
+
|
|
104
|
+
The maximum age of items in the cache.
|
|
105
|
+
|
|
106
|
+
***
|
|
107
|
+
|
|
108
|
+
### Utils\<T\>
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
type Utils<T> = object;
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Defined in: [packages/utils/src/cache.ts:55](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L55)
|
|
115
|
+
|
|
116
|
+
#### Type Parameters
|
|
117
|
+
|
|
118
|
+
##### T
|
|
119
|
+
|
|
120
|
+
`T`
|
|
121
|
+
|
|
122
|
+
#### Properties
|
|
123
|
+
|
|
124
|
+
##### skipCaching()
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
skipCaching: (value) => SkipCaching<T>;
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Defined in: [packages/utils/src/cache.ts:56](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L56)
|
|
131
|
+
|
|
132
|
+
###### Parameters
|
|
133
|
+
|
|
134
|
+
###### value
|
|
135
|
+
|
|
136
|
+
`T`
|
|
137
|
+
|
|
138
|
+
###### Returns
|
|
139
|
+
|
|
140
|
+
[`SkipCaching`](README.md#skipcaching)\<`T`\>
|
|
141
|
+
|
|
142
|
+
##### withExpiration()
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
withExpiration: (value, expiration) => WithExpiration<T>;
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Defined in: [packages/utils/src/cache.ts:62](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L62)
|
|
149
|
+
|
|
150
|
+
Create a new WithExpiration object with the given value and expiration time.
|
|
151
|
+
|
|
152
|
+
###### Parameters
|
|
153
|
+
|
|
154
|
+
###### value
|
|
155
|
+
|
|
156
|
+
`T`
|
|
157
|
+
|
|
158
|
+
The value to store in the cache.
|
|
159
|
+
|
|
160
|
+
###### expiration
|
|
161
|
+
|
|
162
|
+
[`DurationObj`](../time.md#durationobj)
|
|
163
|
+
|
|
164
|
+
The expiration time of the value in seconds or a duration object.
|
|
165
|
+
|
|
166
|
+
###### Returns
|
|
167
|
+
|
|
168
|
+
[`WithExpiration`](README.md#withexpiration)\<`T`\>
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
[**@ls-stack/utils**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](../modules.md) / cache
|
|
6
|
+
|
|
7
|
+
# cache
|
|
8
|
+
|
|
9
|
+
## Modules
|
|
10
|
+
|
|
11
|
+
- [\<internal\>](-internal-.md)
|
|
12
|
+
|
|
13
|
+
## Classes
|
|
14
|
+
|
|
15
|
+
### SkipCaching\<T\>
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/cache.ts:33](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L33)
|
|
18
|
+
|
|
19
|
+
#### Type Parameters
|
|
20
|
+
|
|
21
|
+
##### T
|
|
22
|
+
|
|
23
|
+
`T`
|
|
24
|
+
|
|
25
|
+
#### Constructors
|
|
26
|
+
|
|
27
|
+
##### Constructor
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
new SkipCaching<T>(value): SkipCaching<T>;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Defined in: [packages/utils/src/cache.ts:36](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L36)
|
|
34
|
+
|
|
35
|
+
###### Parameters
|
|
36
|
+
|
|
37
|
+
###### value
|
|
38
|
+
|
|
39
|
+
`T`
|
|
40
|
+
|
|
41
|
+
###### Returns
|
|
42
|
+
|
|
43
|
+
[`SkipCaching`](#skipcaching)\<`T`\>
|
|
44
|
+
|
|
45
|
+
#### Properties
|
|
46
|
+
|
|
47
|
+
##### value
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
value: T;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Defined in: [packages/utils/src/cache.ts:34](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L34)
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### WithExpiration\<T\>
|
|
58
|
+
|
|
59
|
+
Defined in: [packages/utils/src/cache.ts:41](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L41)
|
|
60
|
+
|
|
61
|
+
#### Type Parameters
|
|
62
|
+
|
|
63
|
+
##### T
|
|
64
|
+
|
|
65
|
+
`T`
|
|
66
|
+
|
|
67
|
+
#### Constructors
|
|
68
|
+
|
|
69
|
+
##### Constructor
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
new WithExpiration<T>(value, expiration): WithExpiration<T>;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Defined in: [packages/utils/src/cache.ts:49](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L49)
|
|
76
|
+
|
|
77
|
+
###### Parameters
|
|
78
|
+
|
|
79
|
+
###### value
|
|
80
|
+
|
|
81
|
+
`T`
|
|
82
|
+
|
|
83
|
+
The value to store in the cache.
|
|
84
|
+
|
|
85
|
+
###### expiration
|
|
86
|
+
|
|
87
|
+
[`DurationObj`](../time.md#durationobj)
|
|
88
|
+
|
|
89
|
+
The expiration time of the value in seconds or a duration object.
|
|
90
|
+
|
|
91
|
+
###### Returns
|
|
92
|
+
|
|
93
|
+
[`WithExpiration`](#withexpiration)\<`T`\>
|
|
94
|
+
|
|
95
|
+
#### Properties
|
|
96
|
+
|
|
97
|
+
##### expiration
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
expiration: number;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Defined in: [packages/utils/src/cache.ts:43](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L43)
|
|
104
|
+
|
|
105
|
+
##### value
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
value: T;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Defined in: [packages/utils/src/cache.ts:42](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L42)
|
|
112
|
+
|
|
113
|
+
## Type Aliases
|
|
114
|
+
|
|
115
|
+
### Cache\<T\>
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
type Cache<T> = object;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Defined in: [packages/utils/src/cache.ts:75](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L75)
|
|
122
|
+
|
|
123
|
+
#### Type Parameters
|
|
124
|
+
|
|
125
|
+
##### T
|
|
126
|
+
|
|
127
|
+
`T`
|
|
128
|
+
|
|
129
|
+
#### Properties
|
|
130
|
+
|
|
131
|
+
##### cache
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
cache: object;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Defined in: [packages/utils/src/cache.ts:95](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L95)
|
|
138
|
+
|
|
139
|
+
###### map
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
map: Map<string, {
|
|
143
|
+
timestamp: number;
|
|
144
|
+
value: T | Promise<T>;
|
|
145
|
+
}>;
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
##### cleanExpiredItems()
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
cleanExpiredItems: () => void;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Defined in: [packages/utils/src/cache.ts:89](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L89)
|
|
155
|
+
|
|
156
|
+
###### Returns
|
|
157
|
+
|
|
158
|
+
`void`
|
|
159
|
+
|
|
160
|
+
##### clear()
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
clear: () => void;
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Defined in: [packages/utils/src/cache.ts:86](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L86)
|
|
167
|
+
|
|
168
|
+
###### Returns
|
|
169
|
+
|
|
170
|
+
`void`
|
|
171
|
+
|
|
172
|
+
##### get()
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
get: (cacheKey) => T | undefined;
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Defined in: [packages/utils/src/cache.ts:87](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L87)
|
|
179
|
+
|
|
180
|
+
###### Parameters
|
|
181
|
+
|
|
182
|
+
###### cacheKey
|
|
183
|
+
|
|
184
|
+
`string`
|
|
185
|
+
|
|
186
|
+
###### Returns
|
|
187
|
+
|
|
188
|
+
`T` \| `undefined`
|
|
189
|
+
|
|
190
|
+
##### getAsync()
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
getAsync: (cacheKey) => Promise<T | undefined>;
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Defined in: [packages/utils/src/cache.ts:90](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L90)
|
|
197
|
+
|
|
198
|
+
###### Parameters
|
|
199
|
+
|
|
200
|
+
###### cacheKey
|
|
201
|
+
|
|
202
|
+
`string`
|
|
203
|
+
|
|
204
|
+
###### Returns
|
|
205
|
+
|
|
206
|
+
`Promise`\<`T` \| `undefined`\>
|
|
207
|
+
|
|
208
|
+
##### getOrInsert()
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
getOrInsert: (cacheKey, val, options?) => T;
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Defined in: [packages/utils/src/cache.ts:76](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L76)
|
|
215
|
+
|
|
216
|
+
###### Parameters
|
|
217
|
+
|
|
218
|
+
###### cacheKey
|
|
219
|
+
|
|
220
|
+
`string`
|
|
221
|
+
|
|
222
|
+
###### val
|
|
223
|
+
|
|
224
|
+
(`utils`) => `T` \| [`SkipCaching`](#skipcaching)\<`T`\>
|
|
225
|
+
|
|
226
|
+
###### options?
|
|
227
|
+
|
|
228
|
+
[`GetOptions`](-internal-.md#getoptions)\<`T`\>
|
|
229
|
+
|
|
230
|
+
###### Returns
|
|
231
|
+
|
|
232
|
+
`T`
|
|
233
|
+
|
|
234
|
+
##### getOrInsertAsync()
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
getOrInsertAsync: (cacheKey, val, options?) => Promise<T>;
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Defined in: [packages/utils/src/cache.ts:81](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L81)
|
|
241
|
+
|
|
242
|
+
###### Parameters
|
|
243
|
+
|
|
244
|
+
###### cacheKey
|
|
245
|
+
|
|
246
|
+
`string`
|
|
247
|
+
|
|
248
|
+
###### val
|
|
249
|
+
|
|
250
|
+
(`utils`) => `Promise`\<`T` \| [`SkipCaching`](#skipcaching)\<`T`\>\>
|
|
251
|
+
|
|
252
|
+
###### options?
|
|
253
|
+
|
|
254
|
+
[`GetOptions`](-internal-.md#getoptions)\<`T`\>
|
|
255
|
+
|
|
256
|
+
###### Returns
|
|
257
|
+
|
|
258
|
+
`Promise`\<`T`\>
|
|
259
|
+
|
|
260
|
+
##### set()
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
set: (cacheKey, value) => void;
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Defined in: [packages/utils/src/cache.ts:88](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L88)
|
|
267
|
+
|
|
268
|
+
###### Parameters
|
|
269
|
+
|
|
270
|
+
###### cacheKey
|
|
271
|
+
|
|
272
|
+
`string`
|
|
273
|
+
|
|
274
|
+
###### value
|
|
275
|
+
|
|
276
|
+
`T` | [`WithExpiration`](#withexpiration)\<`T`\>
|
|
277
|
+
|
|
278
|
+
###### Returns
|
|
279
|
+
|
|
280
|
+
`void`
|
|
281
|
+
|
|
282
|
+
##### setAsync()
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
setAsync: (cacheKey, value) => Promise<T>;
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Defined in: [packages/utils/src/cache.ts:91](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L91)
|
|
289
|
+
|
|
290
|
+
###### Parameters
|
|
291
|
+
|
|
292
|
+
###### cacheKey
|
|
293
|
+
|
|
294
|
+
`string`
|
|
295
|
+
|
|
296
|
+
###### value
|
|
297
|
+
|
|
298
|
+
(`utils`) => `Promise`\<`T` \| [`WithExpiration`](#withexpiration)\<`T`\>\>
|
|
299
|
+
|
|
300
|
+
###### Returns
|
|
301
|
+
|
|
302
|
+
`Promise`\<`T`\>
|
|
303
|
+
|
|
304
|
+
## Functions
|
|
305
|
+
|
|
306
|
+
### cachedGetter()
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
function cachedGetter<T>(getter): object;
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
Defined in: [packages/utils/src/cache.ts:3](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L3)
|
|
313
|
+
|
|
314
|
+
#### Type Parameters
|
|
315
|
+
|
|
316
|
+
##### T
|
|
317
|
+
|
|
318
|
+
`T`
|
|
319
|
+
|
|
320
|
+
#### Parameters
|
|
321
|
+
|
|
322
|
+
##### getter
|
|
323
|
+
|
|
324
|
+
() => `T`
|
|
325
|
+
|
|
326
|
+
#### Returns
|
|
327
|
+
|
|
328
|
+
`object`
|
|
329
|
+
|
|
330
|
+
##### value
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
value: T;
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
***
|
|
337
|
+
|
|
338
|
+
### createCache()
|
|
339
|
+
|
|
340
|
+
```ts
|
|
341
|
+
function createCache<T>(__namedParameters): Cache<T>;
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Defined in: [packages/utils/src/cache.ts:100](https://github.com/lucasols/utils/blob/main/packages/utils/src/cache.ts#L100)
|
|
345
|
+
|
|
346
|
+
#### Type Parameters
|
|
347
|
+
|
|
348
|
+
##### T
|
|
349
|
+
|
|
350
|
+
`T`
|
|
351
|
+
|
|
352
|
+
#### Parameters
|
|
353
|
+
|
|
354
|
+
##### \_\_namedParameters
|
|
355
|
+
|
|
356
|
+
[`Options`](-internal-.md#options) = `{}`
|
|
357
|
+
|
|
358
|
+
#### Returns
|
|
359
|
+
|
|
360
|
+
[`Cache`](#cache)\<`T`\>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[**@ls-stack/utils**](README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](modules.md) / castValues
|
|
6
|
+
|
|
7
|
+
# castValues
|
|
8
|
+
|
|
9
|
+
## Functions
|
|
10
|
+
|
|
11
|
+
### castToNumber()
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
function castToNumber(value): null | number;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/castValues.ts:14](https://github.com/lucasols/utils/blob/main/packages/utils/src/castValues.ts#L14)
|
|
18
|
+
|
|
19
|
+
#### Parameters
|
|
20
|
+
|
|
21
|
+
##### value
|
|
22
|
+
|
|
23
|
+
`unknown`
|
|
24
|
+
|
|
25
|
+
#### Returns
|
|
26
|
+
|
|
27
|
+
`null` \| `number`
|
|
28
|
+
|
|
29
|
+
***
|
|
30
|
+
|
|
31
|
+
### castToString()
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
function castToString(value): null | string;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Defined in: [packages/utils/src/castValues.ts:1](https://github.com/lucasols/utils/blob/main/packages/utils/src/castValues.ts#L1)
|
|
38
|
+
|
|
39
|
+
#### Parameters
|
|
40
|
+
|
|
41
|
+
##### value
|
|
42
|
+
|
|
43
|
+
`unknown`
|
|
44
|
+
|
|
45
|
+
#### Returns
|
|
46
|
+
|
|
47
|
+
`null` \| `string`
|