@xylabs/array 4.8.4 → 4.8.5
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/neutral/index.mjs +7 -0
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/filterAsync.d.ts +8 -0
- package/dist/types/filterAsync.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/filterAsync.ts +13 -0
- package/src/index.ts +1 -0
package/dist/neutral/index.mjs
CHANGED
|
@@ -10,6 +10,12 @@ var filterAs = (x, predicate) => {
|
|
|
10
10
|
return x.map(predicate).filter(exists);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
// src/filterAsync.ts
|
|
14
|
+
var filterAsync = async (array, predicate) => {
|
|
15
|
+
const results = await Promise.all(array.map(predicate));
|
|
16
|
+
return array.filter((_, index) => results[index]);
|
|
17
|
+
};
|
|
18
|
+
|
|
13
19
|
// src/findAs.ts
|
|
14
20
|
import { exists as exists2 } from "@xylabs/exists";
|
|
15
21
|
var findAs = (x, predicate) => {
|
|
@@ -44,6 +50,7 @@ export {
|
|
|
44
50
|
containsAll,
|
|
45
51
|
distinct,
|
|
46
52
|
filterAs,
|
|
53
|
+
filterAsync,
|
|
47
54
|
findAs,
|
|
48
55
|
findLastAs,
|
|
49
56
|
flatten,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/containsAll.ts","../../src/distinct.ts","../../src/filterAs.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[]) => array.indexOf(value) === index\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","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,UAAe,MAAM,QAAQ,KAAK,MAAM;;;ACA7F,SAAS,cAAc;AAEhB,IAAM,WAAW,CAAU,GAAS,cAA8B;AACvE,SAAO,EAAE,IAAI,SAAS,EAAE,OAAO,MAAM;AACvC;;;
|
|
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[]) => array.indexOf(value) === index\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,UAAe,MAAM,QAAQ,KAAK,MAAM;;;ACA7F,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"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the elements of an array that meet the condition specified in a callback function.
|
|
3
|
+
* @param array The array to filter.
|
|
4
|
+
* @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.
|
|
5
|
+
* @returns The elements of an array that meet the condition specified in a callback function.
|
|
6
|
+
*/
|
|
7
|
+
export declare const filterAsync: <T>(array: T[], predicate: (value: T, index: number, array: T[]) => Promise<boolean>) => Promise<T[]>;
|
|
8
|
+
//# sourceMappingURL=filterAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterAsync.d.ts","sourceRoot":"","sources":["../../src/filterAsync.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAU,CAAC,EACjC,OAAO,CAAC,EAAE,EACV,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,KACnE,OAAO,CAAC,CAAC,EAAE,CAGb,CAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/array",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.5",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"module": "./dist/neutral/index.mjs",
|
|
36
36
|
"types": "./dist/types/index.d.ts",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@xylabs/exists": "^4.8.
|
|
38
|
+
"@xylabs/exists": "^4.8.5"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@xylabs/ts-scripts-yarn3": "^6.2.1",
|
|
42
42
|
"@xylabs/tsconfig": "^6.2.1",
|
|
43
|
-
"@xylabs/vitest-extended": "^4.8.
|
|
43
|
+
"@xylabs/vitest-extended": "^4.8.5",
|
|
44
44
|
"typescript": "^5.8.3",
|
|
45
45
|
"vitest": "^3.1.1"
|
|
46
46
|
},
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the elements of an array that meet the condition specified in a callback function.
|
|
3
|
+
* @param array The array to filter.
|
|
4
|
+
* @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.
|
|
5
|
+
* @returns The elements of an array that meet the condition specified in a callback function.
|
|
6
|
+
*/
|
|
7
|
+
export const filterAsync = async <T>(
|
|
8
|
+
array: T[],
|
|
9
|
+
predicate: (value: T, index: number, array: T[]) => Promise<boolean>,
|
|
10
|
+
): Promise<T[]> => {
|
|
11
|
+
const results = await Promise.all(array.map(predicate))
|
|
12
|
+
return array.filter((_, index) => results[index])
|
|
13
|
+
}
|