@simplysm/core-common 13.0.99 → 14.0.1
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/common.types.d.ts +14 -14
- package/dist/common.types.js +2 -1
- package/dist/common.types.js.map +1 -6
- package/dist/env.d.ts +5 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +12 -8
- package/dist/env.js.map +1 -6
- package/dist/errors/argument-error.d.ts +10 -10
- package/dist/errors/argument-error.d.ts.map +1 -1
- package/dist/errors/argument-error.js +31 -14
- package/dist/errors/argument-error.js.map +1 -6
- package/dist/errors/not-implemented-error.d.ts +8 -8
- package/dist/errors/not-implemented-error.js +30 -12
- package/dist/errors/not-implemented-error.js.map +1 -6
- package/dist/errors/sd-error.d.ts +10 -10
- package/dist/errors/sd-error.d.ts.map +1 -1
- package/dist/errors/sd-error.js +45 -24
- package/dist/errors/sd-error.js.map +1 -6
- package/dist/errors/timeout-error.d.ts +10 -10
- package/dist/errors/timeout-error.js +34 -15
- package/dist/errors/timeout-error.js.map +1 -6
- package/dist/extensions/arr-ext.d.ts +2 -2
- package/dist/extensions/arr-ext.helpers.d.ts +10 -10
- package/dist/extensions/arr-ext.helpers.js +112 -89
- package/dist/extensions/arr-ext.helpers.js.map +1 -6
- package/dist/extensions/arr-ext.js +458 -422
- package/dist/extensions/arr-ext.js.map +1 -6
- package/dist/extensions/arr-ext.types.d.ts +57 -57
- package/dist/extensions/arr-ext.types.d.ts.map +1 -1
- package/dist/extensions/arr-ext.types.js +6 -1
- package/dist/extensions/arr-ext.types.js.map +1 -6
- package/dist/extensions/map-ext.d.ts +16 -16
- package/dist/extensions/map-ext.js +27 -22
- package/dist/extensions/map-ext.js.map +1 -6
- package/dist/extensions/set-ext.d.ts +11 -11
- package/dist/extensions/set-ext.js +32 -25
- package/dist/extensions/set-ext.js.map +1 -6
- package/dist/features/debounce-queue.d.ts +17 -17
- package/dist/features/debounce-queue.js +98 -70
- package/dist/features/debounce-queue.js.map +1 -6
- package/dist/features/event-emitter.d.ts +20 -20
- package/dist/features/event-emitter.js +101 -78
- package/dist/features/event-emitter.js.map +1 -6
- package/dist/features/serial-queue.d.ts +11 -11
- package/dist/features/serial-queue.js +78 -57
- package/dist/features/serial-queue.js.map +1 -6
- package/dist/globals.d.ts +4 -4
- package/dist/globals.js +9 -1
- package/dist/globals.js.map +1 -6
- package/dist/index.js +28 -27
- package/dist/index.js.map +1 -6
- package/dist/types/date-only.d.ts +64 -64
- package/dist/types/date-only.d.ts.map +1 -1
- package/dist/types/date-only.js +263 -252
- package/dist/types/date-only.js.map +1 -6
- package/dist/types/date-time.d.ts +36 -36
- package/dist/types/date-time.d.ts.map +1 -1
- package/dist/types/date-time.js +196 -288
- package/dist/types/date-time.js.map +1 -6
- package/dist/types/lazy-gc-map.d.ts +26 -26
- package/dist/types/lazy-gc-map.d.ts.map +1 -1
- package/dist/types/lazy-gc-map.js +202 -159
- package/dist/types/lazy-gc-map.js.map +1 -6
- package/dist/types/time.d.ts +23 -23
- package/dist/types/time.d.ts.map +1 -1
- package/dist/types/time.js +169 -158
- package/dist/types/time.js.map +1 -6
- package/dist/types/uuid.d.ts +11 -11
- package/dist/types/uuid.d.ts.map +1 -1
- package/dist/types/uuid.js +95 -70
- package/dist/types/uuid.js.map +1 -6
- package/dist/utils/bytes.d.ts +17 -17
- package/dist/utils/bytes.js +137 -81
- package/dist/utils/bytes.js.map +1 -6
- package/dist/utils/date-format.d.ts +40 -40
- package/dist/utils/date-format.js +187 -101
- package/dist/utils/date-format.js.map +1 -6
- package/dist/utils/error.d.ts +4 -4
- package/dist/utils/error.js +11 -6
- package/dist/utils/error.js.map +1 -6
- package/dist/utils/json.d.ts +19 -19
- package/dist/utils/json.js +187 -135
- package/dist/utils/json.js.map +1 -6
- package/dist/utils/num.d.ts +20 -20
- package/dist/utils/num.js +76 -34
- package/dist/utils/num.js.map +1 -6
- package/dist/utils/obj.d.ts +111 -111
- package/dist/utils/obj.d.ts.map +1 -1
- package/dist/utils/obj.js +706 -496
- package/dist/utils/obj.js.map +1 -6
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/path.js +35 -18
- package/dist/utils/path.js.map +1 -6
- package/dist/utils/primitive.d.ts +5 -5
- package/dist/utils/primitive.js +34 -14
- package/dist/utils/primitive.js.map +1 -6
- package/dist/utils/str.d.ts +38 -38
- package/dist/utils/str.js +217 -113
- package/dist/utils/str.js.map +1 -6
- package/dist/utils/template-strings.d.ts +26 -26
- package/dist/utils/template-strings.js +113 -40
- package/dist/utils/template-strings.js.map +1 -6
- package/dist/utils/transferable.d.ts +18 -18
- package/dist/utils/transferable.js +218 -151
- package/dist/utils/transferable.js.map +1 -6
- package/dist/utils/wait.d.ts +9 -9
- package/dist/utils/wait.js +30 -15
- package/dist/utils/wait.js.map +1 -6
- package/dist/utils/xml.d.ts +13 -13
- package/dist/utils/xml.js +84 -46
- package/dist/utils/xml.js.map +1 -6
- package/dist/utils/zip.d.ts +22 -22
- package/dist/utils/zip.js +172 -148
- package/dist/utils/zip.js.map +1 -6
- package/package.json +5 -7
- package/src/common.types.ts +14 -14
- package/src/env.ts +9 -1
- package/src/errors/argument-error.ts +15 -15
- package/src/errors/not-implemented-error.ts +9 -9
- package/src/errors/sd-error.ts +12 -12
- package/src/errors/timeout-error.ts +12 -12
- package/src/extensions/arr-ext.helpers.ts +16 -16
- package/src/extensions/arr-ext.ts +35 -35
- package/src/extensions/arr-ext.types.ts +57 -57
- package/src/extensions/map-ext.ts +16 -16
- package/src/extensions/set-ext.ts +11 -11
- package/src/features/debounce-queue.ts +23 -23
- package/src/features/event-emitter.ts +25 -25
- package/src/features/serial-queue.ts +13 -13
- package/src/globals.ts +4 -4
- package/src/index.ts +5 -5
- package/src/types/date-only.ts +84 -83
- package/src/types/date-time.ts +43 -42
- package/src/types/lazy-gc-map.ts +44 -44
- package/src/types/time.ts +29 -29
- package/src/types/uuid.ts +15 -15
- package/src/utils/bytes.ts +35 -35
- package/src/utils/date-format.ts +59 -59
- package/src/utils/error.ts +4 -4
- package/src/utils/json.ts +41 -41
- package/src/utils/num.ts +20 -20
- package/src/utils/obj.ts +138 -138
- package/src/utils/path.ts +10 -10
- package/src/utils/primitive.ts +6 -6
- package/src/utils/str.ts +48 -48
- package/src/utils/template-strings.ts +29 -29
- package/src/utils/transferable.ts +38 -38
- package/src/utils/wait.ts +10 -10
- package/src/utils/xml.ts +19 -19
- package/src/utils/zip.ts +25 -25
- package/README.md +0 -160
- package/docs/errors.md +0 -119
- package/docs/extensions.md +0 -387
- package/docs/features.md +0 -143
- package/docs/types.md +0 -287
- package/docs/utils.md +0 -757
- package/tests/errors/errors.spec.ts +0 -80
- package/tests/extensions/array-extension.spec.ts +0 -654
- package/tests/extensions/map-extension.spec.ts +0 -117
- package/tests/extensions/set-extension.spec.ts +0 -67
- package/tests/types/date-only.spec.ts +0 -533
- package/tests/types/date-time.spec.ts +0 -246
- package/tests/types/lazy-gc-map.spec.ts +0 -606
- package/tests/types/time.spec.ts +0 -428
- package/tests/types/uuid.spec.ts +0 -74
- package/tests/utils/bytes-utils.spec.ts +0 -197
- package/tests/utils/date-format.spec.ts +0 -350
- package/tests/utils/debounce-queue.spec.ts +0 -226
- package/tests/utils/json.spec.ts +0 -400
- package/tests/utils/number.spec.ts +0 -136
- package/tests/utils/object.spec.ts +0 -810
- package/tests/utils/path.spec.ts +0 -70
- package/tests/utils/primitive.spec.ts +0 -43
- package/tests/utils/sd-event-emitter.spec.ts +0 -189
- package/tests/utils/serial-queue.spec.ts +0 -305
- package/tests/utils/string.spec.ts +0 -265
- package/tests/utils/template-strings.spec.ts +0 -48
- package/tests/utils/transferable.spec.ts +0 -639
- package/tests/utils/wait.spec.ts +0 -123
- package/tests/utils/xml.spec.ts +0 -146
- package/tests/utils/zip.spec.ts +0 -221
package/docs/extensions.md
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
# Prototype Extensions (side-effect)
|
|
2
|
-
|
|
3
|
-
Prototype extensions for `Array`, `Map`, and `Set`. These are applied as side effects when importing `@simplysm/core-common`.
|
|
4
|
-
|
|
5
|
-
**Important:** Importing the package entry point automatically patches these prototypes. If you import only specific sub-modules, you must also import the extension modules or the entry point to get these methods.
|
|
6
|
-
|
|
7
|
-
Source: `src/extensions/*.ts`
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## Array Extensions
|
|
12
|
-
|
|
13
|
-
### Readonly methods (return new array or value, do not mutate)
|
|
14
|
-
|
|
15
|
-
#### `single`
|
|
16
|
-
|
|
17
|
-
Return single element matching condition. Throws `ArgumentError` if 2+ elements match.
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
single(predicate?: (item: T, index: number) => boolean): T | undefined;
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
#### `first`
|
|
24
|
-
|
|
25
|
-
Return first element.
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
first(predicate?: (item: T, index: number) => boolean): T | undefined;
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
#### `last`
|
|
32
|
-
|
|
33
|
-
Return last element.
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
last(predicate?: (item: T, index: number) => boolean): T | undefined;
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
#### `filterAsync`
|
|
40
|
-
|
|
41
|
-
Async filter (sequential execution).
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
filterAsync(predicate: (item: T, index: number) => Promise<boolean>): Promise<T[]>;
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
#### `filterExists`
|
|
48
|
-
|
|
49
|
-
Remove `null` and `undefined` values.
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
filterExists(): NonNullable<T>[];
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
#### `ofType`
|
|
56
|
-
|
|
57
|
-
Filter only elements of specific type (`PrimitiveTypeStr` or constructor type).
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
ofType<TKey extends PrimitiveTypeStr>(type: TKey): Extract<T, PrimitiveTypeMap[TKey]>[];
|
|
61
|
-
ofType<TNarrow extends T>(type: Type<TNarrow>): TNarrow[];
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
#### `mapAsync`
|
|
65
|
-
|
|
66
|
-
Async mapping (sequential execution).
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
mapAsync<R>(selector: (item: T, index: number) => Promise<R>): Promise<R[]>;
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
#### `mapMany`
|
|
73
|
-
|
|
74
|
-
Flatten nested array, or map then flatten.
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
mapMany(): T extends readonly (infer U)[] ? U[] : T;
|
|
78
|
-
mapMany<R>(selector: (item: T, index: number) => R[]): R[];
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
#### `mapManyAsync`
|
|
82
|
-
|
|
83
|
-
Async mapping and then flatten (sequential execution).
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
mapManyAsync<R>(selector: (item: T, index: number) => Promise<R[]>): Promise<R[]>;
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
#### `parallelAsync`
|
|
90
|
-
|
|
91
|
-
Async parallel processing using `Promise.all`.
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
parallelAsync<R>(fn: (item: T, index: number) => Promise<R>): Promise<R[]>;
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
#### `groupBy`
|
|
98
|
-
|
|
99
|
-
Group by key. O(n) for primitive keys, O(n^2) for object keys (deep comparison).
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
groupBy<K>(keySelector: (item: T, index: number) => K): { key: K; values: T[] }[];
|
|
103
|
-
groupBy<K, V>(
|
|
104
|
-
keySelector: (item: T, index: number) => K,
|
|
105
|
-
valueSelector: (item: T, index: number) => V,
|
|
106
|
-
): { key: K; values: V[] }[];
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
#### `toMap`
|
|
110
|
-
|
|
111
|
-
Convert to `Map`. Throws `ArgumentError` on duplicate keys.
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
toMap<K>(keySelector: (item: T, index: number) => K): Map<K, T>;
|
|
115
|
-
toMap<K, V>(keySelector: (item: T, index: number) => K, valueSelector: (item: T, index: number) => V): Map<K, V>;
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
#### `toMapAsync`
|
|
119
|
-
|
|
120
|
-
Async version of `toMap`.
|
|
121
|
-
|
|
122
|
-
```typescript
|
|
123
|
-
toMapAsync<K>(keySelector: (item: T, index: number) => Promise<K>): Promise<Map<K, T>>;
|
|
124
|
-
toMapAsync<K, V>(
|
|
125
|
-
keySelector: (item: T, index: number) => Promise<K> | K,
|
|
126
|
-
valueSelector: (item: T, index: number) => Promise<V> | V,
|
|
127
|
-
): Promise<Map<K, V>>;
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
#### `toArrayMap`
|
|
131
|
-
|
|
132
|
-
Convert to `Map<K, T[]>` (groups values by key).
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
toArrayMap<K>(keySelector: (item: T, index: number) => K): Map<K, T[]>;
|
|
136
|
-
toArrayMap<K, V>(keySelector: (item: T, index: number) => K, valueSelector: (item: T, index: number) => V): Map<K, V[]>;
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
#### `toSetMap`
|
|
140
|
-
|
|
141
|
-
Convert to `Map<K, Set<T>>`.
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
toSetMap<K>(keySelector: (item: T, index: number) => K): Map<K, Set<T>>;
|
|
145
|
-
toSetMap<K, V>(keySelector: (item: T, index: number) => K, valueSelector: (item: T, index: number) => V): Map<K, Set<V>>;
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
#### `toMapValues`
|
|
149
|
-
|
|
150
|
-
Group by key, then reduce each group's values.
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
toMapValues<K, V>(
|
|
154
|
-
keySelector: (item: T, index: number) => K,
|
|
155
|
-
valueSelector: (items: T[]) => V,
|
|
156
|
-
): Map<K, V>;
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
#### `toObject`
|
|
160
|
-
|
|
161
|
-
Convert to plain object. Throws `ArgumentError` on duplicate keys.
|
|
162
|
-
|
|
163
|
-
```typescript
|
|
164
|
-
toObject(keySelector: (item: T, index: number) => string): Record<string, T>;
|
|
165
|
-
toObject<V>(keySelector: (item: T, index: number) => string, valueSelector: (item: T, index: number) => V): Record<string, V>;
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
#### `toTree`
|
|
169
|
-
|
|
170
|
-
Convert flat array to tree structure. Items with `null`/`undefined` parent key become roots. Uses `toArrayMap` for O(n) complexity.
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
toTree<K extends keyof T, P extends keyof T>(keyProp: K, parentKey: P): TreeArray<T>[];
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
#### `distinct`
|
|
177
|
-
|
|
178
|
-
Remove duplicates. Options: `matchAddress` for reference comparison, `keyFn` for custom key (O(n)). Without `keyFn` on objects: O(n^2).
|
|
179
|
-
|
|
180
|
-
```typescript
|
|
181
|
-
distinct(options?: boolean | { matchAddress?: boolean; keyFn?: (item: T) => string | number }): T[];
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
#### `orderBy` / `orderByDesc`
|
|
185
|
-
|
|
186
|
-
Sort in ascending or descending order. Supports `string`, `number`, `DateTime`, `DateOnly`, `Time`.
|
|
187
|
-
|
|
188
|
-
```typescript
|
|
189
|
-
orderBy(selector?: (item: T) => string | number | DateTime | DateOnly | Time | undefined): T[];
|
|
190
|
-
orderByDesc(selector?: (item: T) => string | number | DateTime | DateOnly | Time | undefined): T[];
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
#### `diffs`
|
|
194
|
-
|
|
195
|
-
Compare two arrays and return INSERT / DELETE / UPDATE results.
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
diffs<P>(target: P[]): ArrayDiffsResult<T, P>[];
|
|
199
|
-
diffs<P>(target: P[], options: { keys: string[]; excludes?: string[] }): ArrayDiffsResult<T, P>[];
|
|
200
|
-
diffs<P>(target: P[], options: { excludes: string[] }): ArrayDiffsResult<T, P>[];
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
#### `oneWayDiffs`
|
|
204
|
-
|
|
205
|
-
One-way diff against original items. Returns `"create"`, `"update"`, or `"same"` for each item.
|
|
206
|
-
|
|
207
|
-
```typescript
|
|
208
|
-
oneWayDiffs<K extends keyof T>(
|
|
209
|
-
orgItems: T[] | Map<T[K], T>,
|
|
210
|
-
keyPropNameOrGetValFn: K | ((item: T) => string | number | undefined),
|
|
211
|
-
options?: { includeSame?: boolean; excludes?: string[]; includes?: string[] },
|
|
212
|
-
): ArrayOneWayDiffResult<T>[];
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
#### `merge`
|
|
216
|
-
|
|
217
|
-
Merge source and target arrays based on diff results.
|
|
218
|
-
|
|
219
|
-
```typescript
|
|
220
|
-
merge<P>(target: P[]): (T | P | (T & P))[];
|
|
221
|
-
merge<P>(target: P[], options: { keys: string[]; excludes?: string[] }): (T | P | (T & P))[];
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
#### `sum`
|
|
225
|
-
|
|
226
|
-
Return sum of elements. Returns `0` for empty arrays.
|
|
227
|
-
|
|
228
|
-
```typescript
|
|
229
|
-
sum(selector?: (item: T, index: number) => number): number;
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
#### `min` / `max`
|
|
233
|
-
|
|
234
|
-
Return minimum or maximum value.
|
|
235
|
-
|
|
236
|
-
```typescript
|
|
237
|
-
min(): T extends number | string ? T | undefined : never;
|
|
238
|
-
min<P extends number | string>(selector?: (item: T, index: number) => P): P | undefined;
|
|
239
|
-
max(): T extends number | string ? T | undefined : never;
|
|
240
|
-
max<P extends number | string>(selector?: (item: T, index: number) => P): P | undefined;
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
#### `shuffle`
|
|
244
|
-
|
|
245
|
-
Return a shuffled copy (Fisher-Yates algorithm).
|
|
246
|
-
|
|
247
|
-
```typescript
|
|
248
|
-
shuffle(): T[];
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
---
|
|
252
|
-
|
|
253
|
-
### Mutable methods (modify original array, marked `@mutates`)
|
|
254
|
-
|
|
255
|
-
#### `distinctThis`
|
|
256
|
-
|
|
257
|
-
Remove duplicates from original array.
|
|
258
|
-
|
|
259
|
-
```typescript
|
|
260
|
-
distinctThis(options?: boolean | { matchAddress?: boolean; keyFn?: (item: T) => string | number }): T[];
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
#### `orderByThis` / `orderByDescThis`
|
|
264
|
-
|
|
265
|
-
Sort original array in ascending or descending order.
|
|
266
|
-
|
|
267
|
-
```typescript
|
|
268
|
-
orderByThis(selector?: (item: T) => string | number | DateTime | DateOnly | Time | undefined): T[];
|
|
269
|
-
orderByDescThis(selector?: (item: T) => string | number | DateTime | DateOnly | Time | undefined): T[];
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
#### `insert`
|
|
273
|
-
|
|
274
|
-
Insert items at index.
|
|
275
|
-
|
|
276
|
-
```typescript
|
|
277
|
-
insert(index: number, ...items: T[]): this;
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
#### `remove`
|
|
281
|
-
|
|
282
|
-
Remove item or items matching condition.
|
|
283
|
-
|
|
284
|
-
```typescript
|
|
285
|
-
remove(item: T): this;
|
|
286
|
-
remove(selector: (item: T, index: number) => boolean): this;
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
#### `toggle`
|
|
290
|
-
|
|
291
|
-
Toggle item in array (remove if exists, add if not).
|
|
292
|
-
|
|
293
|
-
```typescript
|
|
294
|
-
toggle(item: T): this;
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
#### `clear`
|
|
298
|
-
|
|
299
|
-
Clear all items from array.
|
|
300
|
-
|
|
301
|
-
```typescript
|
|
302
|
-
clear(): this;
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
---
|
|
306
|
-
|
|
307
|
-
## Exported Types
|
|
308
|
-
|
|
309
|
-
```typescript
|
|
310
|
-
export type ArrayDiffsResult<TOriginal, TOther> =
|
|
311
|
-
| { source: undefined; target: TOther } // INSERT
|
|
312
|
-
| { source: TOriginal; target: undefined } // DELETE
|
|
313
|
-
| { source: TOriginal; target: TOther }; // UPDATE
|
|
314
|
-
|
|
315
|
-
export type ArrayOneWayDiffResult<TItem> =
|
|
316
|
-
| { type: "create"; item: TItem; orgItem: undefined }
|
|
317
|
-
| { type: "update"; item: TItem; orgItem: TItem }
|
|
318
|
-
| { type: "same"; item: TItem; orgItem: TItem };
|
|
319
|
-
|
|
320
|
-
export type TreeArray<TNode> = TNode & { children: TreeArray<TNode>[] };
|
|
321
|
-
|
|
322
|
-
/** Type that can be sorted/compared */
|
|
323
|
-
export type ComparableType = string | number | boolean | DateTime | DateOnly | Time | undefined;
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
---
|
|
327
|
-
|
|
328
|
-
## Map Extensions
|
|
329
|
-
|
|
330
|
-
#### `getOrCreate`
|
|
331
|
-
|
|
332
|
-
If no value exists for key, set new value and return it. If the second argument is a function, it is called as a factory.
|
|
333
|
-
|
|
334
|
-
```typescript
|
|
335
|
-
getOrCreate(key: K, newValue: V): V;
|
|
336
|
-
getOrCreate(key: K, newValueFn: () => V): V;
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
**Caution:** If `V` is a function type, passing the function directly will be recognized as a factory and called. Wrap it in a factory to store the function itself.
|
|
340
|
-
|
|
341
|
-
#### `update`
|
|
342
|
-
|
|
343
|
-
Update value for key using function. Called even if key does not exist.
|
|
344
|
-
|
|
345
|
-
```typescript
|
|
346
|
-
update(key: K, updateFn: (v: V | undefined) => V): void;
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
**Example:**
|
|
350
|
-
|
|
351
|
-
```typescript
|
|
352
|
-
const countMap = new Map<string, number>();
|
|
353
|
-
countMap.update("key", (v) => (v ?? 0) + 1);
|
|
354
|
-
|
|
355
|
-
map.getOrCreate("users", []).push(newUser);
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
---
|
|
359
|
-
|
|
360
|
-
## Set Extensions
|
|
361
|
-
|
|
362
|
-
#### `adds`
|
|
363
|
-
|
|
364
|
-
Add multiple values at once.
|
|
365
|
-
|
|
366
|
-
```typescript
|
|
367
|
-
adds(...values: T[]): this;
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
#### `toggle`
|
|
371
|
-
|
|
372
|
-
Toggle value (remove if exists, add if not). Optional `addOrDel` parameter to force add or remove.
|
|
373
|
-
|
|
374
|
-
```typescript
|
|
375
|
-
toggle(value: T, addOrDel?: "add" | "del"): this;
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
**Example:**
|
|
379
|
-
|
|
380
|
-
```typescript
|
|
381
|
-
const set = new Set<number>([1, 2, 3]);
|
|
382
|
-
set.toggle(2); // 2 exists, so remove -> {1, 3}
|
|
383
|
-
set.toggle(4); // 4 doesn't exist, so add -> {1, 3, 4}
|
|
384
|
-
|
|
385
|
-
const isAdmin = true;
|
|
386
|
-
set.toggle(5, isAdmin ? "add" : "del"); // Force add
|
|
387
|
-
```
|
package/docs/features.md
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
# Features
|
|
2
|
-
|
|
3
|
-
Feature classes for async control flow and event handling.
|
|
4
|
-
|
|
5
|
-
Source: `src/features/*.ts`
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## `EventEmitter`
|
|
10
|
-
|
|
11
|
-
Type-safe event emitter that can be used in both browsers and Node.js. Internally implemented using `EventTarget`. Supports the `using` statement (`Symbol.dispose`).
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
export class EventEmitter<
|
|
15
|
-
TEvents extends { [K in keyof TEvents]: unknown } = Record<string, unknown>,
|
|
16
|
-
> {
|
|
17
|
-
/**
|
|
18
|
-
* Register an event listener
|
|
19
|
-
* @note Duplicate registration of the same listener to the same event is ignored
|
|
20
|
-
*/
|
|
21
|
-
on<TEventName extends keyof TEvents & string>(
|
|
22
|
-
type: TEventName,
|
|
23
|
-
listener: (data: TEvents[TEventName]) => void,
|
|
24
|
-
): void;
|
|
25
|
-
|
|
26
|
-
/** Remove an event listener */
|
|
27
|
-
off<TEventName extends keyof TEvents & string>(
|
|
28
|
-
type: TEventName,
|
|
29
|
-
listener: (data: TEvents[TEventName]) => void,
|
|
30
|
-
): void;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Emit an event
|
|
34
|
-
* @param args Event data (omitted if void type)
|
|
35
|
-
*/
|
|
36
|
-
emit<TEventName extends keyof TEvents & string>(
|
|
37
|
-
type: TEventName,
|
|
38
|
-
...args: TEvents[TEventName] extends void ? [] : [data: TEvents[TEventName]]
|
|
39
|
-
): void;
|
|
40
|
-
|
|
41
|
-
/** Return the number of listeners for a specific event */
|
|
42
|
-
listenerCount<TEventName extends keyof TEvents & string>(type: TEventName): number;
|
|
43
|
-
|
|
44
|
-
/** Remove all event listeners */
|
|
45
|
-
dispose(): void;
|
|
46
|
-
|
|
47
|
-
[Symbol.dispose](): void;
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
**Example:**
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
interface MyEvents {
|
|
55
|
-
data: string;
|
|
56
|
-
error: Error;
|
|
57
|
-
done: void;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
class MyEmitter extends EventEmitter<MyEvents> {}
|
|
61
|
-
|
|
62
|
-
const emitter = new MyEmitter();
|
|
63
|
-
emitter.on("data", (data) => console.log(data)); // data: string
|
|
64
|
-
emitter.emit("data", "hello");
|
|
65
|
-
emitter.emit("done"); // void type is called without arguments
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## `DebounceQueue`
|
|
71
|
-
|
|
72
|
-
Asynchronous debounce queue. When called multiple times within a short time, only the last request is executed and previous requests are ignored. Extends `EventEmitter<{ error: SdError }>`. Supports the `using` statement.
|
|
73
|
-
|
|
74
|
-
Requests added during execution are processed immediately after the current execution completes without debounce delay.
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
export class DebounceQueue extends EventEmitter<{ error: SdError }> {
|
|
78
|
-
/**
|
|
79
|
-
* @param _delay Debounce delay time (milliseconds). If omitted, executes immediately (next event loop)
|
|
80
|
-
*/
|
|
81
|
-
constructor(delay?: number);
|
|
82
|
-
|
|
83
|
-
/** Clean up pending tasks and timers */
|
|
84
|
-
dispose(): void;
|
|
85
|
-
|
|
86
|
-
[Symbol.dispose](): void;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Add a function to the queue
|
|
90
|
-
* If there was a previously added function, it will be replaced
|
|
91
|
-
*/
|
|
92
|
-
run(fn: () => void | Promise<void>): void;
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
**Error handling:** If there are `"error"` event listeners, errors are emitted as events. Otherwise, errors are logged via `consola`.
|
|
97
|
-
|
|
98
|
-
**Example:**
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
const queue = new DebounceQueue(300); // 300ms delay
|
|
102
|
-
queue.run(() => console.log("1")); // ignored
|
|
103
|
-
queue.run(() => console.log("2")); // ignored
|
|
104
|
-
queue.run(() => console.log("3")); // executed after 300ms
|
|
105
|
-
|
|
106
|
-
queue.on("error", (err) => console.error(err));
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
## `SerialQueue`
|
|
112
|
-
|
|
113
|
-
Asynchronous serial queue. Functions added to the queue are executed sequentially. The next task starts only after one task completes. Subsequent tasks continue to execute even if an error occurs. Extends `EventEmitter<{ error: SdError }>`. Supports the `using` statement.
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
export class SerialQueue extends EventEmitter<{ error: SdError }> {
|
|
117
|
-
/**
|
|
118
|
-
* @param gap Gap between each task (ms). Default: 0
|
|
119
|
-
*/
|
|
120
|
-
constructor(gap?: number);
|
|
121
|
-
|
|
122
|
-
/** Clear pending queue (currently executing task will complete) */
|
|
123
|
-
dispose(): void;
|
|
124
|
-
|
|
125
|
-
[Symbol.dispose](): void;
|
|
126
|
-
|
|
127
|
-
/** Add a function to the queue and execute it */
|
|
128
|
-
run(fn: () => void | Promise<void>): void;
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
**Error handling:** Same as `DebounceQueue` -- emitted as event if listeners exist, otherwise logged.
|
|
133
|
-
|
|
134
|
-
**Example:**
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
const queue = new SerialQueue();
|
|
138
|
-
queue.run(async () => { await fetch("/api/1"); });
|
|
139
|
-
queue.run(async () => { await fetch("/api/2"); }); // executed after 1 completes
|
|
140
|
-
queue.run(async () => { await fetch("/api/3"); }); // executed after 2 completes
|
|
141
|
-
|
|
142
|
-
queue.on("error", (err) => console.error(err));
|
|
143
|
-
```
|