@xylabs/array 5.1.1 → 5.1.3
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
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/containsAll.ts", "../../src/distinct.ts", "../../src/filterAs.ts", "../../src/filterAsync.ts", "../../src/findAs.ts", "../../src/flatten.ts", "../../src/uniq.ts"],
|
|
4
|
+
"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"],
|
|
5
|
+
"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;",
|
|
6
|
+
"names": ["exists", "exists"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/array",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.3",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -40,16 +40,17 @@
|
|
|
40
40
|
"README.md"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@xylabs/exists": "~5.1.
|
|
43
|
+
"@xylabs/exists": "~5.1.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@xylabs/
|
|
46
|
+
"@types/node": "^25.8.0",
|
|
47
|
+
"@xylabs/toolchain": "~8.0.4",
|
|
48
|
+
"@xylabs/tsconfig": "~8.0.4",
|
|
48
49
|
"eslint": "^10.3.0",
|
|
49
|
-
"typescript": "^
|
|
50
|
-
"vite": "^8.0.
|
|
51
|
-
"vitest": "^4.1.
|
|
52
|
-
"@xylabs/vitest-extended": "~5.1.
|
|
50
|
+
"typescript": "^6.0.3",
|
|
51
|
+
"vite": "^8.0.13",
|
|
52
|
+
"vitest": "^4.1.6",
|
|
53
|
+
"@xylabs/vitest-extended": "~5.1.3"
|
|
53
54
|
},
|
|
54
55
|
"engines": {
|
|
55
56
|
"node": ">=18"
|