@xylabs/array 4.2.1 → 4.3.0
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.d.ts +1 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +19 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/uniq.d.ts +3 -0
- package/dist/neutral/uniq.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/uniq.ts +15 -0
package/dist/neutral/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,cAAc,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,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -9,9 +9,27 @@ import { exists } from "@xylabs/exists";
|
|
|
9
9
|
var flatten = (a, b) => {
|
|
10
10
|
return [].concat(a).concat(b).filter(exists);
|
|
11
11
|
};
|
|
12
|
+
|
|
13
|
+
// src/uniq.ts
|
|
14
|
+
var uniq = (arr) => {
|
|
15
|
+
return [...new Set(arr)];
|
|
16
|
+
};
|
|
17
|
+
var uniqBy = (arr, iteratee) => {
|
|
18
|
+
const seen = /* @__PURE__ */ new Set();
|
|
19
|
+
return arr.filter((item) => {
|
|
20
|
+
const key = iteratee(item);
|
|
21
|
+
if (!seen.has(key)) {
|
|
22
|
+
seen.add(key);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
12
28
|
export {
|
|
13
29
|
containsAll,
|
|
14
30
|
distinct,
|
|
15
|
-
flatten
|
|
31
|
+
flatten,
|
|
32
|
+
uniq,
|
|
33
|
+
uniqBy
|
|
16
34
|
};
|
|
17
35
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/containsAll.ts","../../src/distinct.ts","../../src/flatten.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 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"],"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,UAAU,CAAI,GAAwB,MAAgC;AAEjF,SAAQ,CAAC,EAAwB,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,MAAM;AACpE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/containsAll.ts","../../src/distinct.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 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,UAAU,CAAI,GAAwB,MAAgC;AAEjF,SAAQ,CAAC,EAAwB,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,MAAM;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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniq.d.ts","sourceRoot":"","sources":["../../src/uniq.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,GAAI,CAAC,OAAO,CAAC,EAAE,KAAG,CAAC,EAEnC,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,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": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"module": "./dist/neutral/index.mjs",
|
|
36
36
|
"types": "./dist/neutral/index.d.ts",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@xylabs/exists": "^4.
|
|
38
|
+
"@xylabs/exists": "^4.3.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@xylabs/ts-scripts-yarn3": "^4.2.
|
|
42
|
-
"@xylabs/tsconfig": "^4.2.
|
|
41
|
+
"@xylabs/ts-scripts-yarn3": "^4.2.3",
|
|
42
|
+
"@xylabs/tsconfig": "^4.2.3",
|
|
43
43
|
"typescript": "^5.6.3"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
package/src/index.ts
CHANGED
package/src/uniq.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const uniq = <T>(arr: T[]): T[] => {
|
|
2
|
+
return [...new Set(arr)]
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const uniqBy = <T, I>(arr: T[], iteratee: (item: T) => I): T[] => {
|
|
6
|
+
const seen = new Set()
|
|
7
|
+
return arr.filter((item) => {
|
|
8
|
+
const key = iteratee(item)
|
|
9
|
+
if (!seen.has(key)) {
|
|
10
|
+
seen.add(key)
|
|
11
|
+
return true
|
|
12
|
+
}
|
|
13
|
+
return false
|
|
14
|
+
})
|
|
15
|
+
}
|