@x-oasis/unique-array-object 0.1.1

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 ADDED
@@ -0,0 +1,34 @@
1
+ # @x-oasis/unique-array-object
2
+
3
+ keep the last occurrence
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ npm i @x-oasis/unique-array-object
9
+ ```
10
+
11
+ ## How to use
12
+
13
+ ```typescript
14
+ import uniqueArrayObject from '@x-oasis/unique-array-object'
15
+ const state = [
16
+ { name: 'viewable', value: 7 },
17
+ { name: 'imageViewable', value: 9 },
18
+ { name: 'viewable', value: 8 }
19
+ ]
20
+
21
+ uniqueArrayObject(state)
22
+
23
+ // output
24
+ // [
25
+ // { name: 'viewable', value: 8 },
26
+ // { name: 'imageViewable', value: 9 },
27
+ // ]
28
+ ```
29
+
30
+ ## How to run test
31
+
32
+ ```bash
33
+ $ pnpm test
34
+ ```
@@ -0,0 +1,6 @@
1
+ declare const _default: (arr: {
2
+ [key: string]: any;
3
+ }[], getter: string | Function) => {
4
+ [key: string]: any;
5
+ }[];
6
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./unique-array-object.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./unique-array-object.cjs.development.js')
8
+ }
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var index = (function (arr, getter) {
6
+ return [].concat(new Map(arr.filter(function (v) {
7
+ return v;
8
+ }).map(function (item) {
9
+ return [typeof getter === 'function' ? getter(item) : item[getter], item];
10
+ })).values());
11
+ });
12
+
13
+ exports.default = index;
14
+ //# sourceMappingURL=unique-array-object.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unique-array-object.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["// https://stackoverflow.com/a/56757215\n\nexport default (\n arr: Array<{\n [key: string]: any;\n }>,\n getter: string | Function\n) => {\n return [\n ...new Map(\n arr\n .filter((v) => v)\n .map((item) => [\n typeof getter === 'function' ? getter(item) : item[getter],\n item,\n ])\n ).values(),\n ];\n};\n"],"names":["arr","getter","concat","Map","filter","v","map","item","values"],"mappings":";;;;AAEA,aAAe,UACbA,GAEE,EACFC,MAAyB;EAEzB,UAAAC,MAAA,CACK,IAAIC,GAAG,CACRH,GAAG,CACAI,MAAM,CAAC,UAACC,CAAC;IAAA,OAAKA,CAAC;IAAC,CAChBC,GAAG,CAAC,UAACC,IAAI;IAAA,OAAK,CACb,OAAON,MAAM,KAAK,UAAU,GAAGA,MAAM,CAACM,IAAI,CAAC,GAAGA,IAAI,CAACN,MAAM,CAAC,EAC1DM,IAAI,CACL;IAAC,CACL,CAACC,MAAM,EAAE;AAEd,CAAC;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(e,t){return[].concat(new Map(e.filter((function(e){return e})).map((function(e){return["function"==typeof t?t(e):e[t],e]}))).values())};
2
+ //# sourceMappingURL=unique-array-object.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unique-array-object.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["// https://stackoverflow.com/a/56757215\n\nexport default (\n arr: Array<{\n [key: string]: any;\n }>,\n getter: string | Function\n) => {\n return [\n ...new Map(\n arr\n .filter((v) => v)\n .map((item) => [\n typeof getter === 'function' ? getter(item) : item[getter],\n item,\n ])\n ).values(),\n ];\n};\n"],"names":["arr","getter","concat","Map","filter","v","map","item","values"],"mappings":"6FAGEA,EAGAC,GAEA,SAAAC,OACK,IAAIC,IACLH,EACGI,QAAO,SAACC,GAAC,OAAKA,KACdC,KAAI,SAACC,GAAI,MAAK,CACK,mBAAXN,EAAwBA,EAAOM,GAAQA,EAAKN,GACnDM,OAEJC"}
@@ -0,0 +1,10 @@
1
+ var index = (function (arr, getter) {
2
+ return [].concat(new Map(arr.filter(function (v) {
3
+ return v;
4
+ }).map(function (item) {
5
+ return [typeof getter === 'function' ? getter(item) : item[getter], item];
6
+ })).values());
7
+ });
8
+
9
+ export default index;
10
+ //# sourceMappingURL=unique-array-object.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unique-array-object.esm.js","sources":["../src/index.ts"],"sourcesContent":["// https://stackoverflow.com/a/56757215\n\nexport default (\n arr: Array<{\n [key: string]: any;\n }>,\n getter: string | Function\n) => {\n return [\n ...new Map(\n arr\n .filter((v) => v)\n .map((item) => [\n typeof getter === 'function' ? getter(item) : item[getter],\n item,\n ])\n ).values(),\n ];\n};\n"],"names":["arr","getter","concat","Map","filter","v","map","item","values"],"mappings":"AAEA,aAAe,UACbA,GAEE,EACFC,MAAyB;EAEzB,UAAAC,MAAA,CACK,IAAIC,GAAG,CACRH,GAAG,CACAI,MAAM,CAAC,UAACC,CAAC;IAAA,OAAKA,CAAC;IAAC,CAChBC,GAAG,CAAC,UAACC,IAAI;IAAA,OAAK,CACb,OAAON,MAAM,KAAK,UAAU,GAAGA,MAAM,CAACM,IAAI,CAAC,GAAGA,IAAI,CAACN,MAAM,CAAC,EAC1DM,IAAI,CACL;IAAC,CACL,CAACC,MAAM,EAAE;AAEd,CAAC;;;;"}
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@x-oasis/unique-array-object",
3
+ "version": "0.1.1",
4
+ "description": "unique-array-object function",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "module": "dist/unique-array-object.esm.js",
8
+ "files": [
9
+ "dist",
10
+ "index.ts",
11
+ "src"
12
+ ],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "devDependencies": {
16
+ "tsdx": "^0.14.1"
17
+ },
18
+ "scripts": {
19
+ "build": "tsdx build --tsconfig tsconfig.build.json",
20
+ "clean": "rimraf ./dist",
21
+ "test": "vitest",
22
+ "compile": "tsc -p tsconfig.build.json"
23
+ }
24
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ // https://stackoverflow.com/a/56757215
2
+
3
+ export default (
4
+ arr: Array<{
5
+ [key: string]: any;
6
+ }>,
7
+ getter: string | Function
8
+ ) => {
9
+ return [
10
+ ...new Map(
11
+ arr
12
+ .filter((v) => v)
13
+ .map((item) => [
14
+ typeof getter === 'function' ? getter(item) : item[getter],
15
+ item,
16
+ ])
17
+ ).values(),
18
+ ];
19
+ };