@xylabs/array 5.0.84 → 5.0.86

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.
Files changed (2) hide show
  1. package/README.md +91 -156
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -15,6 +15,8 @@
15
15
 
16
16
  Base functionality used throughout XY Labs TypeScript/JavaScript libraries
17
17
 
18
+
19
+
18
20
  ## Reference
19
21
 
20
22
  **@xylabs/array**
@@ -23,15 +25,17 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
23
25
 
24
26
  ## Functions
25
27
 
26
- - [containsAll](#functions/containsAll)
27
- - [distinct](#functions/distinct)
28
- - [filterAs](#functions/filterAs)
29
- - [filterAsync](#functions/filterAsync)
30
- - [findAs](#functions/findAs)
31
- - [findLastAs](#functions/findLastAs)
32
- - [flatten](#functions/flatten)
33
- - [uniq](#functions/uniq)
34
- - [uniqBy](#functions/uniqBy)
28
+ | Function | Description |
29
+ | ------ | ------ |
30
+ | [containsAll](#functions/containsAll) | Checks whether the source array contains every element in the target array. |
31
+ | [distinct](#functions/distinct) | Array filter callback that removes duplicate values, with correct NaN handling. Use with `array.filter(distinct)`. |
32
+ | [filterAs](#functions/filterAs) | Maps each element using the predicate and filters out nullish results. |
33
+ | [filterAsync](#functions/filterAsync) | Returns the elements of an array that meet the condition specified in a callback function. |
34
+ | [findAs](#functions/findAs) | Maps each element using the predicate and returns the first non-nullish result. |
35
+ | [findLastAs](#functions/findLastAs) | Maps each element using the predicate and returns the last non-nullish result. |
36
+ | [flatten](#functions/flatten) | Concatenates two values or arrays into a single flat array, filtering out nullish entries. |
37
+ | [uniq](#functions/uniq) | Returns a new array with duplicate values removed. |
38
+ | [uniqBy](#functions/uniqBy) | Returns a new array with duplicates removed, using a key function for comparison. |
35
39
 
36
40
  ### functions
37
41
 
@@ -42,30 +46,23 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
42
46
  ***
43
47
 
44
48
  ```ts
45
- function containsAll<T>(source, target): boolean;
49
+ function containsAll<T>(source: T[], target: T[]): boolean;
46
50
  ```
47
51
 
48
52
  Checks whether the source array contains every element in the target array.
49
53
 
50
54
  ## Type Parameters
51
55
 
52
- ### T
53
-
54
- `T`
56
+ | Type Parameter |
57
+ | ------ |
58
+ | `T` |
55
59
 
56
60
  ## Parameters
57
61
 
58
- ### source
59
-
60
- `T`[]
61
-
62
- The array to search within
63
-
64
- ### target
65
-
66
- `T`[]
67
-
68
- The elements that must all be present
62
+ | Parameter | Type | Description |
63
+ | ------ | ------ | ------ |
64
+ | `source` | `T`[] | The array to search within |
65
+ | `target` | `T`[] | The elements that must all be present |
69
66
 
70
67
  ## Returns
71
68
 
@@ -81,9 +78,9 @@ True if every target element exists in source
81
78
 
82
79
  ```ts
83
80
  function distinct<T>(
84
- value,
85
- index,
86
- array): boolean;
81
+ value: T,
82
+ index: number,
83
+ array: T[]): boolean;
87
84
  ```
88
85
 
89
86
  Array filter callback that removes duplicate values, with correct NaN handling.
@@ -91,23 +88,17 @@ Use with `array.filter(distinct)`.
91
88
 
92
89
  ## Type Parameters
93
90
 
94
- ### T
95
-
96
- `T`
91
+ | Type Parameter |
92
+ | ------ |
93
+ | `T` |
97
94
 
98
95
  ## Parameters
99
96
 
100
- ### value
101
-
102
- `T`
103
-
104
- ### index
105
-
106
- `number`
107
-
108
- ### array
109
-
110
- `T`[]
97
+ | Parameter | Type |
98
+ | ------ | ------ |
99
+ | `value` | `T` |
100
+ | `index` | `number` |
101
+ | `array` | `T`[] |
111
102
 
112
103
  ## Returns
113
104
 
@@ -120,34 +111,24 @@ Use with `array.filter(distinct)`.
120
111
  ***
121
112
 
122
113
  ```ts
123
- function filterAs<In, Out>(x, predicate): NonNullable<Out>[];
114
+ function filterAs<In, Out>(x: In[], predicate: (a: In) => Out): NonNullable<Out>[];
124
115
  ```
125
116
 
126
117
  Maps each element using the predicate and filters out nullish results.
127
118
 
128
119
  ## Type Parameters
129
120
 
130
- ### In
131
-
132
- `In`
133
-
134
- ### Out
135
-
136
- `Out`
121
+ | Type Parameter |
122
+ | ------ |
123
+ | `In` |
124
+ | `Out` |
137
125
 
138
126
  ## Parameters
139
127
 
140
- ### x
141
-
142
- `In`[]
143
-
144
- The input array
145
-
146
- ### predicate
147
-
148
- (`a`) => `Out`
149
-
150
- Transform function applied to each element
128
+ | Parameter | Type | Description |
129
+ | ------ | ------ | ------ |
130
+ | `x` | `In`[] | The input array |
131
+ | `predicate` | (`a`: `In`) => `Out` | Transform function applied to each element |
151
132
 
152
133
  ## Returns
153
134
 
@@ -162,30 +143,23 @@ Array of non-nullish transformed values
162
143
  ***
163
144
 
164
145
  ```ts
165
- function filterAsync<T>(array, predicate): Promise<T[]>;
146
+ function filterAsync<T>(array: T[], predicate: (value: T, index: number, array: T[]) => Promise<boolean>): Promise<T[]>;
166
147
  ```
167
148
 
168
149
  Returns the elements of an array that meet the condition specified in a callback function.
169
150
 
170
151
  ## Type Parameters
171
152
 
172
- ### T
173
-
174
- `T`
153
+ | Type Parameter |
154
+ | ------ |
155
+ | `T` |
175
156
 
176
157
  ## Parameters
177
158
 
178
- ### array
179
-
180
- `T`[]
181
-
182
- The array to filter.
183
-
184
- ### predicate
185
-
186
- (`value`, `index`, `array`) => `Promise`\<`boolean`\>
187
-
188
- A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
159
+ | Parameter | Type | Description |
160
+ | ------ | ------ | ------ |
161
+ | `array` | `T`[] | The array to filter. |
162
+ | `predicate` | (`value`: `T`, `index`: `number`, `array`: `T`[]) => `Promise`\<`boolean`\> | A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. |
189
163
 
190
164
  ## Returns
191
165
 
@@ -200,34 +174,24 @@ The elements of an array that meet the condition specified in a callback functio
200
174
  ***
201
175
 
202
176
  ```ts
203
- function findAs<In, Out>(x, predicate): NonNullable<Out> | undefined;
177
+ function findAs<In, Out>(x: In[], predicate: (a: In) => Out): NonNullable<Out> | undefined;
204
178
  ```
205
179
 
206
180
  Maps each element using the predicate and returns the first non-nullish result.
207
181
 
208
182
  ## Type Parameters
209
183
 
210
- ### In
211
-
212
- `In`
213
-
214
- ### Out
215
-
216
- `Out`
184
+ | Type Parameter |
185
+ | ------ |
186
+ | `In` |
187
+ | `Out` |
217
188
 
218
189
  ## Parameters
219
190
 
220
- ### x
221
-
222
- `In`[]
223
-
224
- The input array
225
-
226
- ### predicate
227
-
228
- (`a`) => `Out`
229
-
230
- Transform function applied to each element
191
+ | Parameter | Type | Description |
192
+ | ------ | ------ | ------ |
193
+ | `x` | `In`[] | The input array |
194
+ | `predicate` | (`a`: `In`) => `Out` | Transform function applied to each element |
231
195
 
232
196
  ## Returns
233
197
 
@@ -242,34 +206,24 @@ The first non-nullish transformed value, or undefined
242
206
  ***
243
207
 
244
208
  ```ts
245
- function findLastAs<In, Out>(x, predicate): NonNullable<Out> | undefined;
209
+ function findLastAs<In, Out>(x: In[], predicate: (a: In) => Out): NonNullable<Out> | undefined;
246
210
  ```
247
211
 
248
212
  Maps each element using the predicate and returns the last non-nullish result.
249
213
 
250
214
  ## Type Parameters
251
215
 
252
- ### In
253
-
254
- `In`
255
-
256
- ### Out
257
-
258
- `Out`
216
+ | Type Parameter |
217
+ | ------ |
218
+ | `In` |
219
+ | `Out` |
259
220
 
260
221
  ## Parameters
261
222
 
262
- ### x
263
-
264
- `In`[]
265
-
266
- The input array
267
-
268
- ### predicate
269
-
270
- (`a`) => `Out`
271
-
272
- Transform function applied to each element
223
+ | Parameter | Type | Description |
224
+ | ------ | ------ | ------ |
225
+ | `x` | `In`[] | The input array |
226
+ | `predicate` | (`a`: `In`) => `Out` | Transform function applied to each element |
273
227
 
274
228
  ## Returns
275
229
 
@@ -284,30 +238,23 @@ The last non-nullish transformed value, or undefined
284
238
  ***
285
239
 
286
240
  ```ts
287
- function flatten<T>(a?, b?): T[];
241
+ function flatten<T>(a?: T | ConcatArray<T>, b?: T | ConcatArray<T>): T[];
288
242
  ```
289
243
 
290
244
  Concatenates two values or arrays into a single flat array, filtering out nullish entries.
291
245
 
292
246
  ## Type Parameters
293
247
 
294
- ### T
295
-
296
- `T`
248
+ | Type Parameter |
249
+ | ------ |
250
+ | `T` |
297
251
 
298
252
  ## Parameters
299
253
 
300
- ### a?
301
-
302
- First value or array
303
-
304
- `T` | `ConcatArray`\<`T`\>
305
-
306
- ### b?
307
-
308
- Second value or array
309
-
310
- `T` | `ConcatArray`\<`T`\>
254
+ | Parameter | Type | Description |
255
+ | ------ | ------ | ------ |
256
+ | `a?` | `T` \| `ConcatArray`\<`T`\> | First value or array |
257
+ | `b?` | `T` \| `ConcatArray`\<`T`\> | Second value or array |
311
258
 
312
259
  ## Returns
313
260
 
@@ -322,24 +269,22 @@ A flat array of non-nullish elements
322
269
  ***
323
270
 
324
271
  ```ts
325
- function uniq<T>(arr): T[];
272
+ function uniq<T>(arr: T[]): T[];
326
273
  ```
327
274
 
328
275
  Returns a new array with duplicate values removed.
329
276
 
330
277
  ## Type Parameters
331
278
 
332
- ### T
333
-
334
- `T`
279
+ | Type Parameter |
280
+ | ------ |
281
+ | `T` |
335
282
 
336
283
  ## Parameters
337
284
 
338
- ### arr
339
-
340
- `T`[]
341
-
342
- The input array
285
+ | Parameter | Type | Description |
286
+ | ------ | ------ | ------ |
287
+ | `arr` | `T`[] | The input array |
343
288
 
344
289
  ## Returns
345
290
 
@@ -354,34 +299,24 @@ A deduplicated array
354
299
  ***
355
300
 
356
301
  ```ts
357
- function uniqBy<T, I>(arr, iteratee): T[];
302
+ function uniqBy<T, I>(arr: T[], iteratee: (item: T) => I): T[];
358
303
  ```
359
304
 
360
305
  Returns a new array with duplicates removed, using a key function for comparison.
361
306
 
362
307
  ## Type Parameters
363
308
 
364
- ### T
365
-
366
- `T`
367
-
368
- ### I
369
-
370
- `I`
309
+ | Type Parameter |
310
+ | ------ |
311
+ | `T` |
312
+ | `I` |
371
313
 
372
314
  ## Parameters
373
315
 
374
- ### arr
375
-
376
- `T`[]
377
-
378
- The input array
379
-
380
- ### iteratee
381
-
382
- (`item`) => `I`
383
-
384
- Function that returns the key to compare by
316
+ | Parameter | Type | Description |
317
+ | ------ | ------ | ------ |
318
+ | `arr` | `T`[] | The input array |
319
+ | `iteratee` | (`item`: `T`) => `I` | Function that returns the key to compare by |
385
320
 
386
321
  ## Returns
387
322
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/array",
3
- "version": "5.0.84",
3
+ "version": "5.0.86",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "xylabs",
@@ -41,12 +41,12 @@
41
41
  "!**/*.test.*"
42
42
  ],
43
43
  "dependencies": {
44
- "@xylabs/exists": "~5.0.84"
44
+ "@xylabs/exists": "~5.0.86"
45
45
  },
46
46
  "devDependencies": {
47
- "@xylabs/ts-scripts-yarn3": "~7.4.13",
48
- "@xylabs/tsconfig": "~7.4.13",
49
- "@xylabs/vitest-extended": "~5.0.84",
47
+ "@xylabs/ts-scripts-yarn3": "~7.4.16",
48
+ "@xylabs/tsconfig": "~7.4.16",
49
+ "@xylabs/vitest-extended": "~5.0.86",
50
50
  "typescript": "~5.9.3",
51
51
  "vitest": "~4.0.18"
52
52
  },