@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 +13 -0
- package/dist/group-by.cjs.development.js +15 -0
- package/dist/group-by.cjs.development.js.map +1 -0
- package/dist/group-by.cjs.production.min.js +2 -0
- package/dist/group-by.cjs.production.min.js.map +1 -0
- package/dist/group-by.esm.js +11 -0
- package/dist/group-by.esm.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -0
- package/package.json +24 -0
- package/src/index.ts +16 -0
package/README.md
ADDED
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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;;;;"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
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
|