@x-oasis/group-by 0.0.12

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,13 @@
1
+ # @x-oasis/group-by
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ $ npm i @x-oasis/group-by
7
+ ```
8
+
9
+ ## How to use
10
+
11
+ ```typescript
12
+ import groupBy from '@x-oasis/group-by'
13
+ ```
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function groupBy(list, fn) {
6
+ return list.reduce(function (acc, val) {
7
+ var key = fn(val);
8
+ acc[key] = acc[key] || [];
9
+ acc[key].push(val);
10
+ return acc;
11
+ }, {});
12
+ }
13
+
14
+ exports.default = groupBy;
15
+ //# sourceMappingURL=group-by.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-by.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["const hasOwnProperty = Object.prototype.hasOwnProperty\n/**\n * @param list the collection that the method iterates over.\n * @param fn the function that is invoked for every element in the array.\n * @returns\n */\nfunction groupBy(list: any[], fn: Function) {\n return list.reduce((acc, val) => {\n const key = fn(val)\n acc[key] = acc[key] || []\n acc[key].push(val)\n return acc\n }, {})\n}\n\nexport default groupBy\n"],"names":["groupBy","list","fn","reduce","acc","val","key","push"],"mappings":";;;;AAMA,SAASA,OAAOA,CAACC,IAAW,EAAEC,EAAY;EACxC,OAAOD,IAAI,CAACE,MAAM,CAAC,UAACC,GAAG,EAAEC,GAAG;IAC1B,IAAMC,GAAG,GAAGJ,EAAE,CAACG,GAAG,CAAC;IACnBD,GAAG,CAACE,GAAG,CAAC,GAAGF,GAAG,CAACE,GAAG,CAAC,IAAI,EAAE;IACzBF,GAAG,CAACE,GAAG,CAAC,CAACC,IAAI,CAACF,GAAG,CAAC;IAClB,OAAOD,GAAG;GACX,EAAE,EAAE,CAAC;AACR;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(e,r){return e.reduce((function(e,t){var u=r(t);return e[u]=e[u]||[],e[u].push(t),e}),{})};
2
+ //# sourceMappingURL=group-by.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-by.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["const hasOwnProperty = Object.prototype.hasOwnProperty\n/**\n * @param list the collection that the method iterates over.\n * @param fn the function that is invoked for every element in the array.\n * @returns\n */\nfunction groupBy(list: any[], fn: Function) {\n return list.reduce((acc, val) => {\n const key = fn(val)\n acc[key] = acc[key] || []\n acc[key].push(val)\n return acc\n }, {})\n}\n\nexport default groupBy\n"],"names":["list","fn","reduce","acc","val","key","push"],"mappings":"oFAMA,SAAiBA,EAAaC,GAC5B,OAAOD,EAAKE,QAAO,SAACC,EAAKC,GACvB,IAAMC,EAAMJ,EAAGG,GAGf,OAFAD,EAAIE,GAAOF,EAAIE,IAAQ,GACvBF,EAAIE,GAAKC,KAAKF,GACPD,IACN"}
@@ -0,0 +1,11 @@
1
+ function groupBy(list, fn) {
2
+ return list.reduce(function (acc, val) {
3
+ var key = fn(val);
4
+ acc[key] = acc[key] || [];
5
+ acc[key].push(val);
6
+ return acc;
7
+ }, {});
8
+ }
9
+
10
+ export default groupBy;
11
+ //# sourceMappingURL=group-by.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-by.esm.js","sources":["../src/index.ts"],"sourcesContent":["const hasOwnProperty = Object.prototype.hasOwnProperty\n/**\n * @param list the collection that the method iterates over.\n * @param fn the function that is invoked for every element in the array.\n * @returns\n */\nfunction groupBy(list: any[], fn: Function) {\n return list.reduce((acc, val) => {\n const key = fn(val)\n acc[key] = acc[key] || []\n acc[key].push(val)\n return acc\n }, {})\n}\n\nexport default groupBy\n"],"names":["groupBy","list","fn","reduce","acc","val","key","push"],"mappings":"AAMA,SAASA,OAAOA,CAACC,IAAW,EAAEC,EAAY;EACxC,OAAOD,IAAI,CAACE,MAAM,CAAC,UAACC,GAAG,EAAEC,GAAG;IAC1B,IAAMC,GAAG,GAAGJ,EAAE,CAACG,GAAG,CAAC;IACnBD,GAAG,CAACE,GAAG,CAAC,GAAGF,GAAG,CAACE,GAAG,CAAC,IAAI,EAAE;IACzBF,GAAG,CAACE,GAAG,CAAC,CAACC,IAAI,CAACF,GAAG,CAAC;IAClB,OAAOD,GAAG;GACX,EAAE,EAAE,CAAC;AACR;;;;"}
@@ -0,0 +1,2 @@
1
+ declare function groupBy(list: any[], fn: Function): any;
2
+ export default groupBy;
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('./group-by.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./group-by.cjs.development.js')
8
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@x-oasis/group-by",
3
+ "version": "0.0.12",
4
+ "description": "groupBy function",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "module": "dist/groupBy.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,16 @@
1
+ const hasOwnProperty = Object.prototype.hasOwnProperty
2
+ /**
3
+ * @param list the collection that the method iterates over.
4
+ * @param fn the function that is invoked for every element in the array.
5
+ * @returns
6
+ */
7
+ function groupBy(list: any[], fn: Function) {
8
+ return list.reduce((acc, val) => {
9
+ const key = fn(val)
10
+ acc[key] = acc[key] || []
11
+ acc[key].push(val)
12
+ return acc
13
+ }, {})
14
+ }
15
+
16
+ export default groupBy