@xylabs/array 4.11.19 → 4.11.21

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.
@@ -2,7 +2,12 @@
2
2
  var containsAll = (source, target) => target.every((i) => source.includes(i));
3
3
 
4
4
  // src/distinct.ts
5
- var distinct = (value, index, array) => array.indexOf(value) === index;
5
+ var distinct = (value, index, array) => {
6
+ if (Number.isNaN(value)) {
7
+ return array.findIndex((item) => Number.isNaN(item)) === index;
8
+ }
9
+ return array.indexOf(value) === index;
10
+ };
6
11
 
7
12
  // src/filterAs.ts
8
13
  import { exists } from "@xylabs/exists";
@@ -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[]) => 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"]}
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 +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,YAAmC,CAAA"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/array",
3
- "version": "4.11.19",
3
+ "version": "4.11.21",
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.11.19"
38
+ "@xylabs/exists": "^4.11.21"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@xylabs/ts-scripts-yarn3": "^6.5.8",
42
42
  "@xylabs/tsconfig": "^6.5.8",
43
- "@xylabs/vitest-extended": "^4.11.19",
43
+ "@xylabs/vitest-extended": "^4.11.21",
44
44
  "typescript": "^5.8.3",
45
45
  "vitest": "^3.2.3"
46
46
  },
package/src/distinct.ts CHANGED
@@ -1 +1,10 @@
1
- export const distinct = <T>(value: T, index: number, array: T[]) => array.indexOf(value) === index
1
+ export const distinct = <T>(value: T, index: number, array: T[]): boolean => {
2
+ // Special case for NaN
3
+ if (Number.isNaN(value)) {
4
+ // Return true for the first NaN only
5
+ return array.findIndex(item => Number.isNaN(item)) === index
6
+ }
7
+
8
+ // Standard distinct logic for other values
9
+ return array.indexOf(value) === index
10
+ }