@xylabs/array 5.0.83 → 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.
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,29 +46,30 @@ 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
- ## Type Parameters
52
+ Checks whether the source array contains every element in the target array.
49
53
 
50
- ### T
54
+ ## Type Parameters
51
55
 
52
- `T`
56
+ | Type Parameter |
57
+ | ------ |
58
+ | `T` |
53
59
 
54
60
  ## Parameters
55
61
 
56
- ### source
57
-
58
- `T`[]
59
-
60
- ### target
61
-
62
- `T`[]
62
+ | Parameter | Type | Description |
63
+ | ------ | ------ | ------ |
64
+ | `source` | `T`[] | The array to search within |
65
+ | `target` | `T`[] | The elements that must all be present |
63
66
 
64
67
  ## Returns
65
68
 
66
69
  `boolean`
67
70
 
71
+ True if every target element exists in source
72
+
68
73
  ### <a id="distinct"></a>distinct
69
74
 
70
75
  [**@xylabs/array**](#../README)
@@ -73,30 +78,27 @@ function containsAll<T>(source, target): boolean;
73
78
 
74
79
  ```ts
75
80
  function distinct<T>(
76
- value,
77
- index,
78
- array): boolean;
81
+ value: T,
82
+ index: number,
83
+ array: T[]): boolean;
79
84
  ```
80
85
 
81
- ## Type Parameters
86
+ Array filter callback that removes duplicate values, with correct NaN handling.
87
+ Use with `array.filter(distinct)`.
82
88
 
83
- ### T
89
+ ## Type Parameters
84
90
 
85
- `T`
91
+ | Type Parameter |
92
+ | ------ |
93
+ | `T` |
86
94
 
87
95
  ## Parameters
88
96
 
89
- ### value
90
-
91
- `T`
92
-
93
- ### index
94
-
95
- `number`
96
-
97
- ### array
98
-
99
- `T`[]
97
+ | Parameter | Type |
98
+ | ------ | ------ |
99
+ | `value` | `T` |
100
+ | `index` | `number` |
101
+ | `array` | `T`[] |
100
102
 
101
103
  ## Returns
102
104
 
@@ -109,33 +111,31 @@ function distinct<T>(
109
111
  ***
110
112
 
111
113
  ```ts
112
- function filterAs<In, Out>(x, predicate): NonNullable<Out>[];
114
+ function filterAs<In, Out>(x: In[], predicate: (a: In) => Out): NonNullable<Out>[];
113
115
  ```
114
116
 
115
- ## Type Parameters
116
-
117
- ### In
118
-
119
- `In`
117
+ Maps each element using the predicate and filters out nullish results.
120
118
 
121
- ### Out
119
+ ## Type Parameters
122
120
 
123
- `Out`
121
+ | Type Parameter |
122
+ | ------ |
123
+ | `In` |
124
+ | `Out` |
124
125
 
125
126
  ## Parameters
126
127
 
127
- ### x
128
-
129
- `In`[]
130
-
131
- ### predicate
132
-
133
- (`a`) => `Out`
128
+ | Parameter | Type | Description |
129
+ | ------ | ------ | ------ |
130
+ | `x` | `In`[] | The input array |
131
+ | `predicate` | (`a`: `In`) => `Out` | Transform function applied to each element |
134
132
 
135
133
  ## Returns
136
134
 
137
135
  `NonNullable`\<`Out`\>[]
138
136
 
137
+ Array of non-nullish transformed values
138
+
139
139
  ### <a id="filterAsync"></a>filterAsync
140
140
 
141
141
  [**@xylabs/array**](#../README)
@@ -143,30 +143,23 @@ function filterAs<In, Out>(x, predicate): NonNullable<Out>[];
143
143
  ***
144
144
 
145
145
  ```ts
146
- function filterAsync<T>(array, predicate): Promise<T[]>;
146
+ function filterAsync<T>(array: T[], predicate: (value: T, index: number, array: T[]) => Promise<boolean>): Promise<T[]>;
147
147
  ```
148
148
 
149
149
  Returns the elements of an array that meet the condition specified in a callback function.
150
150
 
151
151
  ## Type Parameters
152
152
 
153
- ### T
154
-
155
- `T`
153
+ | Type Parameter |
154
+ | ------ |
155
+ | `T` |
156
156
 
157
157
  ## Parameters
158
158
 
159
- ### array
160
-
161
- `T`[]
162
-
163
- The array to filter.
164
-
165
- ### predicate
166
-
167
- (`value`, `index`, `array`) => `Promise`\<`boolean`\>
168
-
169
- 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. |
170
163
 
171
164
  ## Returns
172
165
 
@@ -181,33 +174,31 @@ The elements of an array that meet the condition specified in a callback functio
181
174
  ***
182
175
 
183
176
  ```ts
184
- function findAs<In, Out>(x, predicate): NonNullable<Out> | undefined;
177
+ function findAs<In, Out>(x: In[], predicate: (a: In) => Out): NonNullable<Out> | undefined;
185
178
  ```
186
179
 
187
- ## Type Parameters
188
-
189
- ### In
180
+ Maps each element using the predicate and returns the first non-nullish result.
190
181
 
191
- `In`
192
-
193
- ### Out
182
+ ## Type Parameters
194
183
 
195
- `Out`
184
+ | Type Parameter |
185
+ | ------ |
186
+ | `In` |
187
+ | `Out` |
196
188
 
197
189
  ## Parameters
198
190
 
199
- ### x
200
-
201
- `In`[]
202
-
203
- ### predicate
204
-
205
- (`a`) => `Out`
191
+ | Parameter | Type | Description |
192
+ | ------ | ------ | ------ |
193
+ | `x` | `In`[] | The input array |
194
+ | `predicate` | (`a`: `In`) => `Out` | Transform function applied to each element |
206
195
 
207
196
  ## Returns
208
197
 
209
198
  `NonNullable`\<`Out`\> \| `undefined`
210
199
 
200
+ The first non-nullish transformed value, or undefined
201
+
211
202
  ### <a id="findLastAs"></a>findLastAs
212
203
 
213
204
  [**@xylabs/array**](#../README)
@@ -215,33 +206,31 @@ function findAs<In, Out>(x, predicate): NonNullable<Out> | undefined;
215
206
  ***
216
207
 
217
208
  ```ts
218
- function findLastAs<In, Out>(x, predicate): NonNullable<Out> | undefined;
209
+ function findLastAs<In, Out>(x: In[], predicate: (a: In) => Out): NonNullable<Out> | undefined;
219
210
  ```
220
211
 
221
- ## Type Parameters
222
-
223
- ### In
224
-
225
- `In`
212
+ Maps each element using the predicate and returns the last non-nullish result.
226
213
 
227
- ### Out
214
+ ## Type Parameters
228
215
 
229
- `Out`
216
+ | Type Parameter |
217
+ | ------ |
218
+ | `In` |
219
+ | `Out` |
230
220
 
231
221
  ## Parameters
232
222
 
233
- ### x
234
-
235
- `In`[]
236
-
237
- ### predicate
238
-
239
- (`a`) => `Out`
223
+ | Parameter | Type | Description |
224
+ | ------ | ------ | ------ |
225
+ | `x` | `In`[] | The input array |
226
+ | `predicate` | (`a`: `In`) => `Out` | Transform function applied to each element |
240
227
 
241
228
  ## Returns
242
229
 
243
230
  `NonNullable`\<`Out`\> \| `undefined`
244
231
 
232
+ The last non-nullish transformed value, or undefined
233
+
245
234
  ### <a id="flatten"></a>flatten
246
235
 
247
236
  [**@xylabs/array**](#../README)
@@ -249,29 +238,30 @@ function findLastAs<In, Out>(x, predicate): NonNullable<Out> | undefined;
249
238
  ***
250
239
 
251
240
  ```ts
252
- function flatten<T>(a?, b?): T[];
241
+ function flatten<T>(a?: T | ConcatArray<T>, b?: T | ConcatArray<T>): T[];
253
242
  ```
254
243
 
255
- ## Type Parameters
244
+ Concatenates two values or arrays into a single flat array, filtering out nullish entries.
256
245
 
257
- ### T
246
+ ## Type Parameters
258
247
 
259
- `T`
248
+ | Type Parameter |
249
+ | ------ |
250
+ | `T` |
260
251
 
261
252
  ## Parameters
262
253
 
263
- ### a?
264
-
265
- `T` | `ConcatArray`\<`T`\>
266
-
267
- ### b?
268
-
269
- `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 |
270
258
 
271
259
  ## Returns
272
260
 
273
261
  `T`[]
274
262
 
263
+ A flat array of non-nullish elements
264
+
275
265
  ### <a id="uniq"></a>uniq
276
266
 
277
267
  [**@xylabs/array**](#../README)
@@ -279,25 +269,29 @@ function flatten<T>(a?, b?): T[];
279
269
  ***
280
270
 
281
271
  ```ts
282
- function uniq<T>(arr): T[];
272
+ function uniq<T>(arr: T[]): T[];
283
273
  ```
284
274
 
285
- ## Type Parameters
275
+ Returns a new array with duplicate values removed.
286
276
 
287
- ### T
277
+ ## Type Parameters
288
278
 
289
- `T`
279
+ | Type Parameter |
280
+ | ------ |
281
+ | `T` |
290
282
 
291
283
  ## Parameters
292
284
 
293
- ### arr
294
-
295
- `T`[]
285
+ | Parameter | Type | Description |
286
+ | ------ | ------ | ------ |
287
+ | `arr` | `T`[] | The input array |
296
288
 
297
289
  ## Returns
298
290
 
299
291
  `T`[]
300
292
 
293
+ A deduplicated array
294
+
301
295
  ### <a id="uniqBy"></a>uniqBy
302
296
 
303
297
  [**@xylabs/array**](#../README)
@@ -305,33 +299,31 @@ function uniq<T>(arr): T[];
305
299
  ***
306
300
 
307
301
  ```ts
308
- function uniqBy<T, I>(arr, iteratee): T[];
302
+ function uniqBy<T, I>(arr: T[], iteratee: (item: T) => I): T[];
309
303
  ```
310
304
 
311
- ## Type Parameters
305
+ Returns a new array with duplicates removed, using a key function for comparison.
312
306
 
313
- ### T
314
-
315
- `T`
316
-
317
- ### I
307
+ ## Type Parameters
318
308
 
319
- `I`
309
+ | Type Parameter |
310
+ | ------ |
311
+ | `T` |
312
+ | `I` |
320
313
 
321
314
  ## Parameters
322
315
 
323
- ### arr
324
-
325
- `T`[]
326
-
327
- ### iteratee
328
-
329
- (`item`) => `I`
316
+ | Parameter | Type | Description |
317
+ | ------ | ------ | ------ |
318
+ | `arr` | `T`[] | The input array |
319
+ | `iteratee` | (`item`: `T`) => `I` | Function that returns the key to compare by |
330
320
 
331
321
  ## Returns
332
322
 
333
323
  `T`[]
334
324
 
325
+ A deduplicated array keeping the first occurrence of each key
326
+
335
327
 
336
328
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
337
329
 
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Checks whether the source array contains every element in the target array.
3
+ * @param source - The array to search within
4
+ * @param target - The elements that must all be present
5
+ * @returns True if every target element exists in source
6
+ */
1
7
  export declare const containsAll: <T>(source: T[], target: T[]) => boolean;
2
8
  //# sourceMappingURL=containsAll.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"containsAll.d.ts","sourceRoot":"","sources":["../../src/containsAll.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,YAA0C,CAAA"}
1
+ {"version":3,"file":"containsAll.d.ts","sourceRoot":"","sources":["../../src/containsAll.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,YAA0C,CAAA"}
@@ -1,2 +1,6 @@
1
+ /**
2
+ * Array filter callback that removes duplicate values, with correct NaN handling.
3
+ * Use with `array.filter(distinct)`.
4
+ */
1
5
  export declare const distinct: <T>(value: T, index: number, array: T[]) => boolean;
2
6
  //# sourceMappingURL=distinct.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"distinct.d.ts","sourceRoot":"","sources":["../../src/distinct.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,EAAE,KAAG,OASjE,CAAA"}
1
+ {"version":3,"file":"distinct.d.ts","sourceRoot":"","sources":["../../src/distinct.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,EAAE,KAAG,OASjE,CAAA"}
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Maps each element using the predicate and filters out nullish results.
3
+ * @param x - The input array
4
+ * @param predicate - Transform function applied to each element
5
+ * @returns Array of non-nullish transformed values
6
+ */
1
7
  export declare const filterAs: <In, Out>(x: In[], predicate: (a: In) => Out) => NonNullable<Out>[];
2
8
  //# sourceMappingURL=filterAs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filterAs.d.ts","sourceRoot":"","sources":["../../src/filterAs.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,GAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC,EAAE,EAAE,KAAK,GAAG,uBAEnE,CAAA"}
1
+ {"version":3,"file":"filterAs.d.ts","sourceRoot":"","sources":["../../src/filterAs.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC,EAAE,EAAE,KAAK,GAAG,uBAEnE,CAAA"}
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Maps each element using the predicate and returns the first non-nullish result.
3
+ * @param x - The input array
4
+ * @param predicate - Transform function applied to each element
5
+ * @returns The first non-nullish transformed value, or undefined
6
+ */
1
7
  export declare const findAs: <In, Out>(x: In[], predicate: (a: In) => Out) => NonNullable<Out> | undefined;
8
+ /**
9
+ * Maps each element using the predicate and returns the last non-nullish result.
10
+ * @param x - The input array
11
+ * @param predicate - Transform function applied to each element
12
+ * @returns The last non-nullish transformed value, or undefined
13
+ */
2
14
  export declare const findLastAs: <In, Out>(x: In[], predicate: (a: In) => Out) => NonNullable<Out> | undefined;
3
15
  //# sourceMappingURL=findAs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"findAs.d.ts","sourceRoot":"","sources":["../../src/findAs.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,GAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC,EAAE,EAAE,KAAK,GAAG,iCAEjE,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC,EAAE,EAAE,KAAK,GAAG,iCAErE,CAAA"}
1
+ {"version":3,"file":"findAs.d.ts","sourceRoot":"","sources":["../../src/findAs.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC,EAAE,EAAE,KAAK,GAAG,iCAEjE,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC,EAAE,EAAE,KAAK,GAAG,iCAErE,CAAA"}
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Concatenates two values or arrays into a single flat array, filtering out nullish entries.
3
+ * @param a - First value or array
4
+ * @param b - Second value or array
5
+ * @returns A flat array of non-nullish elements
6
+ */
1
7
  export declare const flatten: <T>(a?: T | ConcatArray<T>, b?: T | ConcatArray<T>) => T[];
2
8
  //# sourceMappingURL=flatten.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/flatten.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAG,CAAC,EAG5E,CAAA"}
1
+ {"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/flatten.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAG,CAAC,EAG5E,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/containsAll.ts","../../src/distinct.ts","../../src/filterAs.ts","../../src/filterAsync.ts","../../src/findAs.ts","../../src/flatten.ts","../../src/uniq.ts"],"sourcesContent":["export const containsAll = <T>(source: T[], target: T[]) => target.every(i => source.includes(i))\n","export const distinct = <T>(value: T, index: number, array: T[]): boolean => {\n // Special case for NaN\n if (Number.isNaN(value)) {\n // Return true for the first NaN only\n return array.findIndex(item => Number.isNaN(item)) === index\n }\n\n // Standard distinct logic for other values\n return array.indexOf(value) === index\n}\n","import { exists } from '@xylabs/exists'\n\nexport const filterAs = <In, Out>(x: In[], predicate: (a: In) => Out) => {\n return x.map(predicate).filter(exists)\n}\n","/**\n * Returns the elements of an array that meet the condition specified in a callback function.\n * @param array The array to filter.\n * @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.\n * @returns The elements of an array that meet the condition specified in a callback function.\n */\nexport const filterAsync = async <T>(\n array: T[],\n predicate: (value: T, index: number, array: T[]) => Promise<boolean>,\n): Promise<T[]> => {\n const results = await Promise.all(array.map(predicate))\n return array.filter((_, index) => results[index])\n}\n","import { exists } from '@xylabs/exists'\n\nexport const findAs = <In, Out>(x: In[], predicate: (a: In) => Out) => {\n return x.map(predicate).find(exists)\n}\n\nexport const findLastAs = <In, Out>(x: In[], predicate: (a: In) => Out) => {\n return x.map(predicate).findLast(exists)\n}\n","import { exists } from '@xylabs/exists'\n\nexport const flatten = <T>(a?: T | ConcatArray<T>, b?: T | ConcatArray<T>): T[] => {\n // eslint-disable-next-line unicorn/prefer-spread\n return ([] as (T | undefined)[]).concat(a).concat(b).filter(exists)\n}\n","export const uniq = <T>(arr: T[]): T[] => {\n return [...new Set(arr)]\n}\n\nexport const uniqBy = <T, I>(arr: T[], iteratee: (item: T) => I): T[] => {\n const seen = new Set()\n return arr.filter((item) => {\n const key = iteratee(item)\n if (!seen.has(key)) {\n seen.add(key)\n return true\n }\n return false\n })\n}\n"],"mappings":";AAAO,IAAM,cAAc,CAAI,QAAa,WAAgB,OAAO,MAAM,OAAK,OAAO,SAAS,CAAC,CAAC;;;ACAzF,IAAM,WAAW,CAAI,OAAU,OAAe,UAAwB;AAE3E,MAAI,OAAO,MAAM,KAAK,GAAG;AAEvB,WAAO,MAAM,UAAU,UAAQ,OAAO,MAAM,IAAI,CAAC,MAAM;AAAA,EACzD;AAGA,SAAO,MAAM,QAAQ,KAAK,MAAM;AAClC;;;ACTA,SAAS,cAAc;AAEhB,IAAM,WAAW,CAAU,GAAS,cAA8B;AACvE,SAAO,EAAE,IAAI,SAAS,EAAE,OAAO,MAAM;AACvC;;;ACEO,IAAM,cAAc,OACzB,OACA,cACiB;AACjB,QAAM,UAAU,MAAM,QAAQ,IAAI,MAAM,IAAI,SAAS,CAAC;AACtD,SAAO,MAAM,OAAO,CAAC,GAAG,UAAU,QAAQ,KAAK,CAAC;AAClD;;;ACZA,SAAS,UAAAA,eAAc;AAEhB,IAAM,SAAS,CAAU,GAAS,cAA8B;AACrE,SAAO,EAAE,IAAI,SAAS,EAAE,KAAKA,OAAM;AACrC;AAEO,IAAM,aAAa,CAAU,GAAS,cAA8B;AACzE,SAAO,EAAE,IAAI,SAAS,EAAE,SAASA,OAAM;AACzC;;;ACRA,SAAS,UAAAC,eAAc;AAEhB,IAAM,UAAU,CAAI,GAAwB,MAAgC;AAEjF,SAAQ,CAAC,EAAwB,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,OAAOA,OAAM;AACpE;;;ACLO,IAAM,OAAO,CAAI,QAAkB;AACxC,SAAO,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC;AACzB;AAEO,IAAM,SAAS,CAAO,KAAU,aAAkC;AACvE,QAAM,OAAO,oBAAI,IAAI;AACrB,SAAO,IAAI,OAAO,CAAC,SAAS;AAC1B,UAAM,MAAM,SAAS,IAAI;AACzB,QAAI,CAAC,KAAK,IAAI,GAAG,GAAG;AAClB,WAAK,IAAI,GAAG;AACZ,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AACH;","names":["exists","exists"]}
1
+ {"version":3,"sources":["../../src/containsAll.ts","../../src/distinct.ts","../../src/filterAs.ts","../../src/filterAsync.ts","../../src/findAs.ts","../../src/flatten.ts","../../src/uniq.ts"],"sourcesContent":["/**\n * Checks whether the source array contains every element in the target array.\n * @param source - The array to search within\n * @param target - The elements that must all be present\n * @returns True if every target element exists in source\n */\nexport const containsAll = <T>(source: T[], target: T[]) => target.every(i => source.includes(i))\n","/**\n * Array filter callback that removes duplicate values, with correct NaN handling.\n * Use with `array.filter(distinct)`.\n */\nexport const distinct = <T>(value: T, index: number, array: T[]): boolean => {\n // Special case for NaN\n if (Number.isNaN(value)) {\n // Return true for the first NaN only\n return array.findIndex(item => Number.isNaN(item)) === index\n }\n\n // Standard distinct logic for other values\n return array.indexOf(value) === index\n}\n","import { exists } from '@xylabs/exists'\n\n/**\n * Maps each element using the predicate and filters out nullish results.\n * @param x - The input array\n * @param predicate - Transform function applied to each element\n * @returns Array of non-nullish transformed values\n */\nexport const filterAs = <In, Out>(x: In[], predicate: (a: In) => Out) => {\n return x.map(predicate).filter(exists)\n}\n","/**\n * Returns the elements of an array that meet the condition specified in a callback function.\n * @param array The array to filter.\n * @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.\n * @returns The elements of an array that meet the condition specified in a callback function.\n */\nexport const filterAsync = async <T>(\n array: T[],\n predicate: (value: T, index: number, array: T[]) => Promise<boolean>,\n): Promise<T[]> => {\n const results = await Promise.all(array.map(predicate))\n return array.filter((_, index) => results[index])\n}\n","import { exists } from '@xylabs/exists'\n\n/**\n * Maps each element using the predicate and returns the first non-nullish result.\n * @param x - The input array\n * @param predicate - Transform function applied to each element\n * @returns The first non-nullish transformed value, or undefined\n */\nexport const findAs = <In, Out>(x: In[], predicate: (a: In) => Out) => {\n return x.map(predicate).find(exists)\n}\n\n/**\n * Maps each element using the predicate and returns the last non-nullish result.\n * @param x - The input array\n * @param predicate - Transform function applied to each element\n * @returns The last non-nullish transformed value, or undefined\n */\nexport const findLastAs = <In, Out>(x: In[], predicate: (a: In) => Out) => {\n return x.map(predicate).findLast(exists)\n}\n","import { exists } from '@xylabs/exists'\n\n/**\n * Concatenates two values or arrays into a single flat array, filtering out nullish entries.\n * @param a - First value or array\n * @param b - Second value or array\n * @returns A flat array of non-nullish elements\n */\nexport const flatten = <T>(a?: T | ConcatArray<T>, b?: T | ConcatArray<T>): T[] => {\n // eslint-disable-next-line unicorn/prefer-spread\n return ([] as (T | undefined)[]).concat(a).concat(b).filter(exists)\n}\n","/**\n * Returns a new array with duplicate values removed.\n * @param arr - The input array\n * @returns A deduplicated array\n */\nexport const uniq = <T>(arr: T[]): T[] => {\n return [...new Set(arr)]\n}\n\n/**\n * Returns a new array with duplicates removed, using a key function for comparison.\n * @param arr - The input array\n * @param iteratee - Function that returns the key to compare by\n * @returns A deduplicated array keeping the first occurrence of each key\n */\nexport const uniqBy = <T, I>(arr: T[], iteratee: (item: T) => I): T[] => {\n const seen = new Set()\n return arr.filter((item) => {\n const key = iteratee(item)\n if (!seen.has(key)) {\n seen.add(key)\n return true\n }\n return false\n })\n}\n"],"mappings":";AAMO,IAAM,cAAc,CAAI,QAAa,WAAgB,OAAO,MAAM,OAAK,OAAO,SAAS,CAAC,CAAC;;;ACFzF,IAAM,WAAW,CAAI,OAAU,OAAe,UAAwB;AAE3E,MAAI,OAAO,MAAM,KAAK,GAAG;AAEvB,WAAO,MAAM,UAAU,UAAQ,OAAO,MAAM,IAAI,CAAC,MAAM;AAAA,EACzD;AAGA,SAAO,MAAM,QAAQ,KAAK,MAAM;AAClC;;;ACbA,SAAS,cAAc;AAQhB,IAAM,WAAW,CAAU,GAAS,cAA8B;AACvE,SAAO,EAAE,IAAI,SAAS,EAAE,OAAO,MAAM;AACvC;;;ACJO,IAAM,cAAc,OACzB,OACA,cACiB;AACjB,QAAM,UAAU,MAAM,QAAQ,IAAI,MAAM,IAAI,SAAS,CAAC;AACtD,SAAO,MAAM,OAAO,CAAC,GAAG,UAAU,QAAQ,KAAK,CAAC;AAClD;;;ACZA,SAAS,UAAAA,eAAc;AAQhB,IAAM,SAAS,CAAU,GAAS,cAA8B;AACrE,SAAO,EAAE,IAAI,SAAS,EAAE,KAAKA,OAAM;AACrC;AAQO,IAAM,aAAa,CAAU,GAAS,cAA8B;AACzE,SAAO,EAAE,IAAI,SAAS,EAAE,SAASA,OAAM;AACzC;;;ACpBA,SAAS,UAAAC,eAAc;AAQhB,IAAM,UAAU,CAAI,GAAwB,MAAgC;AAEjF,SAAQ,CAAC,EAAwB,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,OAAOA,OAAM;AACpE;;;ACNO,IAAM,OAAO,CAAI,QAAkB;AACxC,SAAO,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC;AACzB;AAQO,IAAM,SAAS,CAAO,KAAU,aAAkC;AACvE,QAAM,OAAO,oBAAI,IAAI;AACrB,SAAO,IAAI,OAAO,CAAC,SAAS;AAC1B,UAAM,MAAM,SAAS,IAAI;AACzB,QAAI,CAAC,KAAK,IAAI,GAAG,GAAG;AAClB,WAAK,IAAI,GAAG;AACZ,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AACH;","names":["exists","exists"]}
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Returns a new array with duplicate values removed.
3
+ * @param arr - The input array
4
+ * @returns A deduplicated array
5
+ */
1
6
  export declare const uniq: <T>(arr: T[]) => T[];
7
+ /**
8
+ * Returns a new array with duplicates removed, using a key function for comparison.
9
+ * @param arr - The input array
10
+ * @param iteratee - Function that returns the key to compare by
11
+ * @returns A deduplicated array keeping the first occurrence of each key
12
+ */
2
13
  export declare const uniqBy: <T, I>(arr: T[], iteratee: (item: T) => I) => T[];
3
14
  //# sourceMappingURL=uniq.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uniq.d.ts","sourceRoot":"","sources":["../../src/uniq.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,KAAK,CAAC,EAAE,KAAG,CAAC,EAEnC,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAG,CAAC,EAUlE,CAAA"}
1
+ {"version":3,"file":"uniq.d.ts","sourceRoot":"","sources":["../../src/uniq.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,KAAK,CAAC,EAAE,KAAG,CAAC,EAEnC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAG,CAAC,EAUlE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/array",
3
- "version": "5.0.83",
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.83"
44
+ "@xylabs/exists": "~5.0.86"
45
45
  },
46
46
  "devDependencies": {
47
- "@xylabs/ts-scripts-yarn3": "~7.4.11",
48
- "@xylabs/tsconfig": "~7.4.11",
49
- "@xylabs/vitest-extended": "~5.0.83",
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
  },