array-group-to-record
Advanced tools
| 'use strict' | ||
| if (typeof process !== 'undefined' && process.env.NODE_ENV === 'production') { | ||
| module.exports = require('./index.cjs.production.min.cjs') | ||
| } else { | ||
| module.exports = require('./index.cjs.development.cjs') | ||
| } |
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| var hashSum = require('hash-sum'); | ||
| function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
| var hashSum__default = /*#__PURE__*/_interopDefaultLegacy(hashSum); | ||
| function handleOptions(options) { | ||
| var _options$getKey; | ||
| const getKey = (_options$getKey = options === null || options === void 0 ? void 0 : options.getKey) !== null && _options$getKey !== void 0 ? _options$getKey : item => hashSum__default["default"](item); | ||
| return { ...options, | ||
| getKey | ||
| }; | ||
| } | ||
| function arrayGroupToRecord(arr, options) { | ||
| var _init; | ||
| const { | ||
| getKey, | ||
| init | ||
| } = handleOptions(options); | ||
| return arr.reduce((map, item, index, arr) => { | ||
| var _map$id; | ||
| const id = getKey(item, index, arr); | ||
| (_map$id = map[id]) !== null && _map$id !== void 0 ? _map$id : map[id] = []; | ||
| map[id].push(item); | ||
| return map; | ||
| }, (_init = init === null || init === void 0 ? void 0 : init()) !== null && _init !== void 0 ? _init : {}); | ||
| } | ||
| function arrayGroupToMap(arr, options) { | ||
| var _init2; | ||
| const { | ||
| getKey, | ||
| init | ||
| } = handleOptions(options); | ||
| return arr.reduce((map, item, index, arr) => { | ||
| var _map$get; | ||
| const id = getKey(item, index, arr); | ||
| const a = (_map$get = map.get(id)) !== null && _map$get !== void 0 ? _map$get : []; | ||
| a.push(item); | ||
| map.set(id, a); | ||
| return map; | ||
| }, (_init2 = init === null || init === void 0 ? void 0 : init()) !== null && _init2 !== void 0 ? _init2 : new Map()); | ||
| } | ||
| function sumGroup(group) { | ||
| let len = 0; | ||
| if (typeof group.forEach === 'undefined') { | ||
| group = Object.values(group); | ||
| } | ||
| group.forEach(b => len += b.length); | ||
| return len; | ||
| } | ||
| exports.arrayGroupToMap = arrayGroupToMap; | ||
| exports.arrayGroupToRecord = arrayGroupToRecord; | ||
| exports["default"] = arrayGroupToRecord; | ||
| exports.handleOptions = handleOptions; | ||
| exports.sumGroup = sumGroup; | ||
| //# sourceMappingURL=index.cjs.development.cjs.map |
| {"version":3,"file":"index.cjs.development.cjs","sources":["../src/index.ts"],"sourcesContent":["import hashSum from 'hash-sum';\n\nexport interface IOptionsForRecord<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): string\n\n\tinit?(): Record<string, T[]>,\n}\n\nexport interface IOptionsForMap<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): any\n\n\tinit?(): Map<any, T[]>,\n}\n\nexport function handleOptions<O extends IOptionsForRecord<any> | IOptionsForMap<any>>(options: O): O\n{\n\tconst getKey = options?.getKey ?? ((item) => hashSum(item));\n\n\treturn {\n\t\t...options,\n\t\tgetKey,\n\t}\n}\n\nexport function arrayGroupToRecord<T>(arr: T[], options?: IOptionsForRecord<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tmap[id] ??= [];\n\t\tmap[id].push(item);\n\n\t\treturn map\n\t}, init?.() ?? {} as Record<string, T[]>);\n}\n\nexport function arrayGroupToMap<T>(arr: T[], options?: IOptionsForMap<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tconst a = map.get(id) ?? [];\n\n\t\ta.push(item);\n\n\t\tmap.set(id, a);\n\n\t\treturn map\n\t}, init?.() ?? new Map() as Map<any, T[]>);\n}\n\nexport function sumGroup<T extends Record<any, any[]> | Map<any, any[]>>(group: T)\n{\n\tlet len = 0;\n\n\tif (typeof group.forEach === 'undefined')\n\t{\n\t\t// @ts-ignore\n\t\tgroup = Object.values(group);\n\t}\n\n\t// @ts-ignore\n\tgroup.forEach(b => len += b.length);\n\n\treturn len;\n}\n\nexport default arrayGroupToRecord\n"],"names":["handleOptions","options","getKey","item","hashSum","arrayGroupToRecord","arr","init","reduce","map","index","id","push","arrayGroupToMap","a","get","set","Map","sumGroup","group","len","forEach","Object","values","b","length"],"mappings":"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"} |
| "use strict";function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var e=_interopDefaultLegacy(require("hash-sum"));function handleOptions(r){var o;const t=null!==(o=null==r?void 0:r.getKey)&&void 0!==o?o:r=>e.default(r);return{...r,getKey:t}}function arrayGroupToRecord(e,r){var o;const{getKey:t,init:n}=handleOptions(r);return e.reduce(((e,r,o,n)=>{var u;const a=t(r,o,n);return null!==(u=e[a])&&void 0!==u||(e[a]=[]),e[a].push(r),e}),null!==(o=null==n?void 0:n())&&void 0!==o?o:{})}exports.arrayGroupToMap=function arrayGroupToMap(e,r){var o;const{getKey:t,init:n}=handleOptions(r);return e.reduce(((e,r,o,n)=>{var u;const a=t(r,o,n),l=null!==(u=e.get(a))&&void 0!==u?u:[];return l.push(r),e.set(a,l),e}),null!==(o=null==n?void 0:n())&&void 0!==o?o:new Map)},exports.arrayGroupToRecord=arrayGroupToRecord,exports.default=arrayGroupToRecord,exports.handleOptions=handleOptions,exports.sumGroup=function sumGroup(e){let r=0;return void 0===e.forEach&&(e=Object.values(e)),e.forEach((e=>r+=e.length)),r}; | ||
| //# sourceMappingURL=index.cjs.production.min.cjs.map |
| {"version":3,"file":"index.cjs.production.min.cjs","sources":["../src/index.ts"],"sourcesContent":["import hashSum from 'hash-sum';\n\nexport interface IOptionsForRecord<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): string\n\n\tinit?(): Record<string, T[]>,\n}\n\nexport interface IOptionsForMap<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): any\n\n\tinit?(): Map<any, T[]>,\n}\n\nexport function handleOptions<O extends IOptionsForRecord<any> | IOptionsForMap<any>>(options: O): O\n{\n\tconst getKey = options?.getKey ?? ((item) => hashSum(item));\n\n\treturn {\n\t\t...options,\n\t\tgetKey,\n\t}\n}\n\nexport function arrayGroupToRecord<T>(arr: T[], options?: IOptionsForRecord<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tmap[id] ??= [];\n\t\tmap[id].push(item);\n\n\t\treturn map\n\t}, init?.() ?? {} as Record<string, T[]>);\n}\n\nexport function arrayGroupToMap<T>(arr: T[], options?: IOptionsForMap<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tconst a = map.get(id) ?? [];\n\n\t\ta.push(item);\n\n\t\tmap.set(id, a);\n\n\t\treturn map\n\t}, init?.() ?? new Map() as Map<any, T[]>);\n}\n\nexport function sumGroup<T extends Record<any, any[]> | Map<any, any[]>>(group: T)\n{\n\tlet len = 0;\n\n\tif (typeof group.forEach === 'undefined')\n\t{\n\t\t// @ts-ignore\n\t\tgroup = Object.values(group);\n\t}\n\n\t// @ts-ignore\n\tgroup.forEach(b => len += b.length);\n\n\treturn len;\n}\n\nexport default arrayGroupToRecord\n"],"names":["handleOptions","options","_options$getKey","getKey","item","hashSum","arrayGroupToRecord","arr","_init","init","reduce","map","index","_map$id","id","push","arrayGroupToMap","_init2","_map$get","a","get","set","Map","sumGroup","group","len","forEach","Object","values","b","length"],"mappings":"iNAgBM,SAAUA,cAAsEC,GAAU,IAAAC,EAE/F,MAAMC,UAAMD,EAAGD,MAAAA,OAAAA,EAAAA,EAASE,sBAAYC,GAASC,UAAQD,GAErD,MAAO,IACHH,EACHE,OAAAA,GAIc,SAAAG,mBAAsBC,EAAUN,GAA8B,IAAAO,EAE7E,MAAML,OAAEA,EAAFM,KAAUA,GAAST,cAAcC,GAEvC,OAAOM,EAAIG,QAAO,CAACC,EAAKP,EAAMQ,EAAOL,KAAO,IAAAM,EAG3C,MAAMC,EAAKX,EAAOC,EAAMQ,EAAOL,GAK/B,OAHA,QAAAI,EAAAA,EAAIG,UAAJ,IAAAD,IAAAF,EAAIG,GAAQ,IACZH,EAAIG,GAAIC,KAAKX,GAENO,IACO,QATRH,EASJC,MAAAA,SAAAA,WAAY,IAAAD,EAAAA,EAAA,4BAGA,SAAAQ,gBAAmBT,EAAUN,GAA2B,IAAAgB,EAEvE,MAAMd,OAAEA,EAAFM,KAAUA,GAAST,cAAcC,GAEvC,OAAOM,EAAIG,QAAO,CAACC,EAAKP,EAAMQ,EAAOL,KAAO,IAAAW,EAG3C,MAAMJ,EAAKX,EAAOC,EAAMQ,EAAOL,GAEzBY,EAAC,UAAGR,EAAIS,IAAIN,UAAX,IAAAI,EAAAA,EAAkB,GAMzB,OAJAC,EAAEJ,KAAKX,GAEPO,EAAIU,IAAIP,EAAIK,GAELR,IACO,QAZRM,EAYJR,MAAAA,OAZI,EAYJA,WAAY,IAAAQ,EAAAA,EAAA,IAAIK,4IAGd,SAAUC,SAAyDC,GAExE,IAAIC,EAAM,EAWV,YAT6B,IAAlBD,EAAME,UAGhBF,EAAQG,OAAOC,OAAOJ,IAIvBA,EAAME,SAAQG,GAAKJ,GAAOI,EAAEC,SAErBL"} |
| import r from "hash-sum"; | ||
| function handleOptions(o) { | ||
| var n; | ||
| const e = null !== (n = null == o ? void 0 : o.getKey) && void 0 !== n ? n : o => r(o); | ||
| return { | ||
| ...o, | ||
| getKey: e | ||
| }; | ||
| } | ||
| function arrayGroupToRecord(r, o) { | ||
| var n; | ||
| const {getKey: e, init: u} = handleOptions(o); | ||
| return r.reduce(((r, o, n, u) => { | ||
| var t; | ||
| const a = e(o, n, u); | ||
| return null !== (t = r[a]) && void 0 !== t || (r[a] = []), r[a].push(o), r; | ||
| }), null !== (n = null == u ? void 0 : u()) && void 0 !== n ? n : {}); | ||
| } | ||
| function arrayGroupToMap(r, o) { | ||
| var n; | ||
| const {getKey: e, init: u} = handleOptions(o); | ||
| return r.reduce(((r, o, n, u) => { | ||
| var t; | ||
| const a = e(o, n, u), l = null !== (t = r.get(a)) && void 0 !== t ? t : []; | ||
| return l.push(o), r.set(a, l), r; | ||
| }), null !== (n = null == u ? void 0 : u()) && void 0 !== n ? n : new Map); | ||
| } | ||
| function sumGroup(r) { | ||
| let o = 0; | ||
| return void 0 === r.forEach && (r = Object.values(r)), r.forEach((r => o += r.length)), | ||
| o; | ||
| } | ||
| export { arrayGroupToMap, arrayGroupToRecord, arrayGroupToRecord as default, handleOptions, sumGroup }; | ||
| //# sourceMappingURL=index.esm.mjs.map |
| {"version":3,"file":"index.esm.mjs","sources":["../src/index.ts"],"sourcesContent":["import hashSum from 'hash-sum';\n\nexport interface IOptionsForRecord<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): string\n\n\tinit?(): Record<string, T[]>,\n}\n\nexport interface IOptionsForMap<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): any\n\n\tinit?(): Map<any, T[]>,\n}\n\nexport function handleOptions<O extends IOptionsForRecord<any> | IOptionsForMap<any>>(options: O): O\n{\n\tconst getKey = options?.getKey ?? ((item) => hashSum(item));\n\n\treturn {\n\t\t...options,\n\t\tgetKey,\n\t}\n}\n\nexport function arrayGroupToRecord<T>(arr: T[], options?: IOptionsForRecord<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tmap[id] ??= [];\n\t\tmap[id].push(item);\n\n\t\treturn map\n\t}, init?.() ?? {} as Record<string, T[]>);\n}\n\nexport function arrayGroupToMap<T>(arr: T[], options?: IOptionsForMap<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tconst a = map.get(id) ?? [];\n\n\t\ta.push(item);\n\n\t\tmap.set(id, a);\n\n\t\treturn map\n\t}, init?.() ?? new Map() as Map<any, T[]>);\n}\n\nexport function sumGroup<T extends Record<any, any[]> | Map<any, any[]>>(group: T)\n{\n\tlet len = 0;\n\n\tif (typeof group.forEach === 'undefined')\n\t{\n\t\t// @ts-ignore\n\t\tgroup = Object.values(group);\n\t}\n\n\t// @ts-ignore\n\tgroup.forEach(b => len += b.length);\n\n\treturn len;\n}\n\nexport default arrayGroupToRecord\n"],"names":["handleOptions","options","_options$getKey","getKey","item","hashSum","arrayGroupToRecord","arr","_init","init","reduce","map","index","_map$id","id","push","arrayGroupToMap","_init2","_map$get","a","get","set","Map","sumGroup","group","len","forEach","Object","values","b","length"],"mappings":";;AAgBM,SAAUA,cAAsEC;EAAU,IAAAC;EAE/F,MAAMC,cAAMD,IAAGD,QAAAA,SAAAA,IAAAA,EAASE,8BAAYC,KAASC,EAAQD;EAErD,OAAO;OACHH;IACHE,QAAAA;;;;AAIc,SAAAG,mBAAsBC,GAAUN;EAA8B,IAAAO;EAE7E,OAAML,QAAEA,GAAFM,MAAUA,KAAST,cAAcC;EAEvC,OAAOM,EAAIG,QAAO,CAACC,GAAKP,GAAMQ,GAAOL;IAAO,IAAAM;IAG3C,MAAMC,IAAKX,EAAOC,GAAMQ,GAAOL;IAK/B,OAHA,UAAAI,IAAAA,EAAIG,YAAJ,MAAAD,MAAAF,EAAIG,KAAQ,KACZH,EAAIG,GAAIC,KAAKX,IAENO;MACO,UATRH,IASJC,QAAAA,aAAAA,aAAY,MAAAD,IAAAA,IAAA;;;AAGA,SAAAQ,gBAAmBT,GAAUN;EAA2B,IAAAgB;EAEvE,OAAMd,QAAEA,GAAFM,MAAUA,KAAST,cAAcC;EAEvC,OAAOM,EAAIG,QAAO,CAACC,GAAKP,GAAMQ,GAAOL;IAAO,IAAAW;IAG3C,MAAMJ,IAAKX,EAAOC,GAAMQ,GAAOL,IAEzBY,IAAC,cAAGR,EAAIS,IAAIN,YAAX,MAAAI,IAAAA,IAAkB;IAMzB,OAJAC,EAAEJ,KAAKX,IAEPO,EAAIU,IAAIP,GAAIK,IAELR;MACO,UAZRM,IAYJR,QAAAA,SAZI,IAYJA,aAAY,MAAAQ,IAAAA,IAAA,IAAIK;;;AAGd,SAAUC,SAAyDC;EAExE,IAAIC,IAAM;EAWV,YAT6B,MAAlBD,EAAME,YAGhBF,IAAQG,OAAOC,OAAOJ,KAIvBA,EAAME,SAAQG,KAAKJ,KAAOI,EAAEC;EAErBL;;;"} |
| (function (global, factory) { | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('hash-sum')) : | ||
| typeof define === 'function' && define.amd ? define(['exports', 'hash-sum'], factory) : | ||
| (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.index = {}, global.hashSum)); | ||
| })(this, (function (exports, hashSum) { 'use strict'; | ||
| function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
| var hashSum__default = /*#__PURE__*/_interopDefaultLegacy(hashSum); | ||
| function handleOptions(options) { | ||
| var _options$getKey; | ||
| const getKey = (_options$getKey = options === null || options === void 0 ? void 0 : options.getKey) !== null && _options$getKey !== void 0 ? _options$getKey : item => hashSum__default["default"](item); | ||
| return { ...options, | ||
| getKey | ||
| }; | ||
| } | ||
| function arrayGroupToRecord(arr, options) { | ||
| var _init; | ||
| const { | ||
| getKey, | ||
| init | ||
| } = handleOptions(options); | ||
| return arr.reduce((map, item, index, arr) => { | ||
| var _map$id; | ||
| const id = getKey(item, index, arr); | ||
| (_map$id = map[id]) !== null && _map$id !== void 0 ? _map$id : map[id] = []; | ||
| map[id].push(item); | ||
| return map; | ||
| }, (_init = init === null || init === void 0 ? void 0 : init()) !== null && _init !== void 0 ? _init : {}); | ||
| } | ||
| function arrayGroupToMap(arr, options) { | ||
| var _init2; | ||
| const { | ||
| getKey, | ||
| init | ||
| } = handleOptions(options); | ||
| return arr.reduce((map, item, index, arr) => { | ||
| var _map$get; | ||
| const id = getKey(item, index, arr); | ||
| const a = (_map$get = map.get(id)) !== null && _map$get !== void 0 ? _map$get : []; | ||
| a.push(item); | ||
| map.set(id, a); | ||
| return map; | ||
| }, (_init2 = init === null || init === void 0 ? void 0 : init()) !== null && _init2 !== void 0 ? _init2 : new Map()); | ||
| } | ||
| function sumGroup(group) { | ||
| let len = 0; | ||
| if (typeof group.forEach === 'undefined') { | ||
| group = Object.values(group); | ||
| } | ||
| group.forEach(b => len += b.length); | ||
| return len; | ||
| } | ||
| exports.arrayGroupToMap = arrayGroupToMap; | ||
| exports.arrayGroupToRecord = arrayGroupToRecord; | ||
| exports["default"] = arrayGroupToRecord; | ||
| exports.handleOptions = handleOptions; | ||
| exports.sumGroup = sumGroup; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| })); | ||
| //# sourceMappingURL=index.umd.development.cjs.map |
| {"version":3,"file":"index.umd.development.cjs","sources":["../src/index.ts"],"sourcesContent":["import hashSum from 'hash-sum';\n\nexport interface IOptionsForRecord<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): string\n\n\tinit?(): Record<string, T[]>,\n}\n\nexport interface IOptionsForMap<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): any\n\n\tinit?(): Map<any, T[]>,\n}\n\nexport function handleOptions<O extends IOptionsForRecord<any> | IOptionsForMap<any>>(options: O): O\n{\n\tconst getKey = options?.getKey ?? ((item) => hashSum(item));\n\n\treturn {\n\t\t...options,\n\t\tgetKey,\n\t}\n}\n\nexport function arrayGroupToRecord<T>(arr: T[], options?: IOptionsForRecord<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tmap[id] ??= [];\n\t\tmap[id].push(item);\n\n\t\treturn map\n\t}, init?.() ?? {} as Record<string, T[]>);\n}\n\nexport function arrayGroupToMap<T>(arr: T[], options?: IOptionsForMap<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tconst a = map.get(id) ?? [];\n\n\t\ta.push(item);\n\n\t\tmap.set(id, a);\n\n\t\treturn map\n\t}, init?.() ?? new Map() as Map<any, T[]>);\n}\n\nexport function sumGroup<T extends Record<any, any[]> | Map<any, any[]>>(group: T)\n{\n\tlet len = 0;\n\n\tif (typeof group.forEach === 'undefined')\n\t{\n\t\t// @ts-ignore\n\t\tgroup = Object.values(group);\n\t}\n\n\t// @ts-ignore\n\tgroup.forEach(b => len += b.length);\n\n\treturn len;\n}\n\nexport default arrayGroupToRecord\n"],"names":["handleOptions","options","getKey","item","hashSum","arrayGroupToRecord","arr","init","reduce","map","index","id","push","arrayGroupToMap","a","get","set","Map","sumGroup","group","len","forEach","Object","values","b","length"],"mappings":"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"} |
| !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("hash-sum")):"function"==typeof define&&define.amd?define(["exports","hash-sum"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).index={},e.hashSum)}(this,(function(e,o){"use strict";function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=_interopDefaultLegacy(o);function handleOptions(e){var o;const t=null!==(o=null==e?void 0:e.getKey)&&void 0!==o?o:e=>n.default(e);return{...e,getKey:t}}function arrayGroupToRecord(e,o){var n;const{getKey:t,init:r}=handleOptions(o);return e.reduce(((e,o,n,r)=>{var u;const a=t(o,n,r);return null!==(u=e[a])&&void 0!==u||(e[a]=[]),e[a].push(o),e}),null!==(n=null==r?void 0:r())&&void 0!==n?n:{})}e.arrayGroupToMap=function arrayGroupToMap(e,o){var n;const{getKey:t,init:r}=handleOptions(o);return e.reduce(((e,o,n,r)=>{var u;const a=t(o,n,r),i=null!==(u=e.get(a))&&void 0!==u?u:[];return i.push(o),e.set(a,i),e}),null!==(n=null==r?void 0:r())&&void 0!==n?n:new Map)},e.arrayGroupToRecord=arrayGroupToRecord,e.default=arrayGroupToRecord,e.handleOptions=handleOptions,e.sumGroup=function sumGroup(e){let o=0;return void 0===e.forEach&&(e=Object.values(e)),e.forEach((e=>o+=e.length)),o},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
| //# sourceMappingURL=index.umd.production.min.cjs.map |
| {"version":3,"file":"index.umd.production.min.cjs","sources":["../src/index.ts"],"sourcesContent":["import hashSum from 'hash-sum';\n\nexport interface IOptionsForRecord<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): string\n\n\tinit?(): Record<string, T[]>,\n}\n\nexport interface IOptionsForMap<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): any\n\n\tinit?(): Map<any, T[]>,\n}\n\nexport function handleOptions<O extends IOptionsForRecord<any> | IOptionsForMap<any>>(options: O): O\n{\n\tconst getKey = options?.getKey ?? ((item) => hashSum(item));\n\n\treturn {\n\t\t...options,\n\t\tgetKey,\n\t}\n}\n\nexport function arrayGroupToRecord<T>(arr: T[], options?: IOptionsForRecord<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tmap[id] ??= [];\n\t\tmap[id].push(item);\n\n\t\treturn map\n\t}, init?.() ?? {} as Record<string, T[]>);\n}\n\nexport function arrayGroupToMap<T>(arr: T[], options?: IOptionsForMap<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tconst a = map.get(id) ?? [];\n\n\t\ta.push(item);\n\n\t\tmap.set(id, a);\n\n\t\treturn map\n\t}, init?.() ?? new Map() as Map<any, T[]>);\n}\n\nexport function sumGroup<T extends Record<any, any[]> | Map<any, any[]>>(group: T)\n{\n\tlet len = 0;\n\n\tif (typeof group.forEach === 'undefined')\n\t{\n\t\t// @ts-ignore\n\t\tgroup = Object.values(group);\n\t}\n\n\t// @ts-ignore\n\tgroup.forEach(b => len += b.length);\n\n\treturn len;\n}\n\nexport default arrayGroupToRecord\n"],"names":["handleOptions","options","_options$getKey","getKey","item","hashSum","arrayGroupToRecord","arr","_init","init","reduce","map","index","_map$id","id","push","arrayGroupToMap","_init2","_map$get","a","get","set","Map","sumGroup","group","len","forEach","Object","values","b","length"],"mappings":"mZAgBM,SAAUA,cAAsEC,GAAU,IAAAC,EAE/F,MAAMC,UAAMD,EAAGD,MAAAA,OAAAA,EAAAA,EAASE,sBAAYC,GAASC,UAAQD,GAErD,MAAO,IACHH,EACHE,OAAAA,GAIc,SAAAG,mBAAsBC,EAAUN,GAA8B,IAAAO,EAE7E,MAAML,OAAEA,EAAFM,KAAUA,GAAST,cAAcC,GAEvC,OAAOM,EAAIG,QAAO,CAACC,EAAKP,EAAMQ,EAAOL,KAAO,IAAAM,EAG3C,MAAMC,EAAKX,EAAOC,EAAMQ,EAAOL,GAK/B,OAHA,QAAAI,EAAAA,EAAIG,UAAJ,IAAAD,IAAAF,EAAIG,GAAQ,IACZH,EAAIG,GAAIC,KAAKX,GAENO,IACO,QATRH,EASJC,MAAAA,SAAAA,WAAY,IAAAD,EAAAA,EAAA,sBAGA,SAAAQ,gBAAmBT,EAAUN,GAA2B,IAAAgB,EAEvE,MAAMd,OAAEA,EAAFM,KAAUA,GAAST,cAAcC,GAEvC,OAAOM,EAAIG,QAAO,CAACC,EAAKP,EAAMQ,EAAOL,KAAO,IAAAW,EAG3C,MAAMJ,EAAKX,EAAOC,EAAMQ,EAAOL,GAEzBY,EAAC,UAAGR,EAAIS,IAAIN,UAAX,IAAAI,EAAAA,EAAkB,GAMzB,OAJAC,EAAEJ,KAAKX,GAEPO,EAAIU,IAAIP,EAAIK,GAELR,IACO,QAZRM,EAYJR,MAAAA,OAZI,EAYJA,WAAY,IAAAQ,EAAAA,EAAA,IAAIK,oHAGd,SAAUC,SAAyDC,GAExE,IAAIC,EAAM,EAWV,YAT6B,IAAlBD,EAAME,UAGhBF,EAAQG,OAAOC,OAAOJ,IAIvBA,EAAME,SAAQG,GAAKJ,GAAOI,EAAEC,SAErBL"} |
+16
-0
@@ -6,2 +6,18 @@ # Change Log | ||
| ## [1.0.4](https://github.com/bluelovers/ws-array/compare/array-group-to-record@1.0.3...array-group-to-record@1.0.4) (2022-06-01) | ||
| ### 🛠 Build System | ||
| * update tsdx ([2fd45ba](https://github.com/bluelovers/ws-array/commit/2fd45ba88a6190b28828eecff56a1d8152817ccb)) | ||
| ### ♻️ Chores | ||
| * **deps:** update deps ([b49fe32](https://github.com/bluelovers/ws-array/commit/b49fe32dd2967e3912a35f620ba7534097425a2a)) | ||
| ## [1.0.3](https://github.com/bluelovers/ws-array/compare/array-group-to-record@1.0.1...array-group-to-record@1.0.3) (2021-11-27) | ||
@@ -8,0 +24,0 @@ |
+19
-5
| { | ||
| "name": "array-group-to-record", | ||
| "version": "1.0.3", | ||
| "version": "1.0.4", | ||
| "description": "", | ||
| "keywords": [ | ||
| "create-by-yarn-tool", | ||
| "create-by-tsdx" | ||
| ], | ||
| "homepage": "https://github.com/bluelovers/ws-array/tree/master/packages/array-group-to-record#readme", | ||
@@ -15,6 +19,16 @@ "bugs": { | ||
| "author": "bluelovers", | ||
| "main": "dist/index.js", | ||
| "module": "dist/index.esm.js", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.esm.mjs", | ||
| "require": "./dist/index.cjs" | ||
| } | ||
| }, | ||
| "main": "dist/index.cjs", | ||
| "module": "dist/index.esm.mjs", | ||
| "types": "dist/index.d.ts", | ||
| "typings": "dist/index.d.ts", | ||
| "directories": { | ||
| "test": "test" | ||
| }, | ||
| "scripts": { | ||
@@ -45,3 +59,3 @@ "coverage": "yarn run test -- --coverage", | ||
| "hash-sum": "^2.0.0", | ||
| "tslib": "^2.3.1" | ||
| "tslib": "^2" | ||
| }, | ||
@@ -52,3 +66,3 @@ "devDependencies": { | ||
| "packageManager": "yarn@^1.22.11", | ||
| "gitHead": "66c6ce9f0fabca879b3384016b1f2a3463a29353" | ||
| "gitHead": "69e8484ee268f8c2640a5df3714075a46a6c0e11" | ||
| } |
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| var hashSum = require('hash-sum'); | ||
| function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
| var hashSum__default = /*#__PURE__*/_interopDefaultLegacy(hashSum); | ||
| function handleOptions(options) { | ||
| var _options$getKey; | ||
| const getKey = (_options$getKey = options === null || options === void 0 ? void 0 : options.getKey) !== null && _options$getKey !== void 0 ? _options$getKey : item => hashSum__default["default"](item); | ||
| return { ...options, | ||
| getKey | ||
| }; | ||
| } | ||
| function arrayGroupToRecord(arr, options) { | ||
| var _init; | ||
| const { | ||
| getKey, | ||
| init | ||
| } = handleOptions(options); | ||
| return arr.reduce((map, item, index, arr) => { | ||
| var _map$id; | ||
| const id = getKey(item, index, arr); | ||
| (_map$id = map[id]) !== null && _map$id !== void 0 ? _map$id : map[id] = []; | ||
| map[id].push(item); | ||
| return map; | ||
| }, (_init = init === null || init === void 0 ? void 0 : init()) !== null && _init !== void 0 ? _init : {}); | ||
| } | ||
| function arrayGroupToMap(arr, options) { | ||
| var _init2; | ||
| const { | ||
| getKey, | ||
| init | ||
| } = handleOptions(options); | ||
| return arr.reduce((map, item, index, arr) => { | ||
| var _map$get; | ||
| const id = getKey(item, index, arr); | ||
| const a = (_map$get = map.get(id)) !== null && _map$get !== void 0 ? _map$get : []; | ||
| a.push(item); | ||
| map.set(id, a); | ||
| return map; | ||
| }, (_init2 = init === null || init === void 0 ? void 0 : init()) !== null && _init2 !== void 0 ? _init2 : new Map()); | ||
| } | ||
| function sumGroup(group) { | ||
| let len = 0; | ||
| if (typeof group.forEach === 'undefined') { | ||
| group = Object.values(group); | ||
| } | ||
| group.forEach(b => len += b.length); | ||
| return len; | ||
| } | ||
| exports.arrayGroupToMap = arrayGroupToMap; | ||
| exports.arrayGroupToRecord = arrayGroupToRecord; | ||
| exports["default"] = arrayGroupToRecord; | ||
| exports.handleOptions = handleOptions; | ||
| exports.sumGroup = sumGroup; | ||
| //# sourceMappingURL=index.cjs.development.js.map |
| {"version":3,"file":"index.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["import hashSum from 'hash-sum';\n\nexport interface IOptionsForRecord<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): string\n\n\tinit?(): Record<string, T[]>,\n}\n\nexport interface IOptionsForMap<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): any\n\n\tinit?(): Map<any, T[]>,\n}\n\nexport function handleOptions<O extends IOptionsForRecord<any> | IOptionsForMap<any>>(options: O): O\n{\n\tconst getKey = options?.getKey ?? ((item) => hashSum(item));\n\n\treturn {\n\t\t...options,\n\t\tgetKey,\n\t}\n}\n\nexport function arrayGroupToRecord<T>(arr: T[], options?: IOptionsForRecord<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tmap[id] ??= [];\n\t\tmap[id].push(item);\n\n\t\treturn map\n\t}, init?.() ?? {} as Record<string, T[]>);\n}\n\nexport function arrayGroupToMap<T>(arr: T[], options?: IOptionsForMap<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tconst a = map.get(id) ?? [];\n\n\t\ta.push(item);\n\n\t\tmap.set(id, a);\n\n\t\treturn map\n\t}, init?.() ?? new Map() as Map<any, T[]>);\n}\n\nexport function sumGroup<T extends Record<any, any[]> | Map<any, any[]>>(group: T)\n{\n\tlet len = 0;\n\n\tif (typeof group.forEach === 'undefined')\n\t{\n\t\t// @ts-ignore\n\t\tgroup = Object.values(group);\n\t}\n\n\t// @ts-ignore\n\tgroup.forEach(b => len += b.length);\n\n\treturn len;\n}\n\nexport default arrayGroupToRecord\n"],"names":["handleOptions","options","getKey","item","hashSum","arrayGroupToRecord","arr","init","reduce","map","index","id","push","arrayGroupToMap","a","get","set","Map","sumGroup","group","len","forEach","Object","values","b","length"],"mappings":";;;;;;;;;;SAgBgBA,cAAsEC;;;AAErF,QAAMC,MAAM,sBAAGD,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEC,MAAZ,6DAAwBC,IAAD,IAAUC,2BAAO,CAACD,IAAD,CAApD;AAEA,SAAO,EACN,GAAGF,OADG;AAENC,IAAAA;AAFM,GAAP;AAIA;SAEeG,mBAAsBC,KAAUL;;;AAE/C,QAAM;AAAEC,IAAAA,MAAF;AAAUK,IAAAA;AAAV,MAAmBP,aAAa,CAACC,OAAD,CAAtC;AAEA,SAAOK,GAAG,CAACE,MAAJ,CAAW,CAACC,GAAD,EAAMN,IAAN,EAAYO,KAAZ,EAAmBJ,GAAnB;;;AAGjB,UAAMK,EAAE,GAAGT,MAAM,CAACC,IAAD,EAAOO,KAAP,EAAcJ,GAAd,CAAjB;AAEA,eAAAG,GAAG,CAACE,EAAD,CAAH,6CAAAF,GAAG,CAACE,EAAD,CAAH,GAAY,EAAZ;AACAF,IAAAA,GAAG,CAACE,EAAD,CAAH,CAAQC,IAAR,CAAaT,IAAb;AAEA,WAAOM,GAAP;AACA,GATM,WASJF,IATI,aASJA,IATI,uBASJA,IAAI,EATA,yCASQ,EATR,CAAP;AAUA;SAEeM,gBAAmBP,KAAUL;;;AAE5C,QAAM;AAAEC,IAAAA,MAAF;AAAUK,IAAAA;AAAV,MAAmBP,aAAa,CAACC,OAAD,CAAtC;AAEA,SAAOK,GAAG,CAACE,MAAJ,CAAW,CAACC,GAAD,EAAMN,IAAN,EAAYO,KAAZ,EAAmBJ,GAAnB;;;AAGjB,UAAMK,EAAE,GAAGT,MAAM,CAACC,IAAD,EAAOO,KAAP,EAAcJ,GAAd,CAAjB;AAEA,UAAMQ,CAAC,eAAGL,GAAG,CAACM,GAAJ,CAAQJ,EAAR,CAAH,+CAAkB,EAAzB;AAEAG,IAAAA,CAAC,CAACF,IAAF,CAAOT,IAAP;AAEAM,IAAAA,GAAG,CAACO,GAAJ,CAAQL,EAAR,EAAYG,CAAZ;AAEA,WAAOL,GAAP;AACA,GAZM,YAYJF,IAZI,aAYJA,IAZI,uBAYJA,IAAI,EAZA,2CAYQ,IAAIU,GAAJ,EAZR,CAAP;AAaA;SAEeC,SAAyDC;AAExE,MAAIC,GAAG,GAAG,CAAV;;AAEA,MAAI,OAAOD,KAAK,CAACE,OAAb,KAAyB,WAA7B,EACA;AAECF,IAAAA,KAAK,GAAGG,MAAM,CAACC,MAAP,CAAcJ,KAAd,CAAR;AACA;;AAGDA,EAAAA,KAAK,CAACE,OAAN,CAAcG,CAAC,IAAIJ,GAAG,IAAII,CAAC,CAACC,MAA5B;AAEA,SAAOL,GAAP;AACA;;;;;;;;"} |
| "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("hash-sum"));function r(e){var r;const n=null!==(r=null==e?void 0:e.getKey)&&void 0!==r?r:e=>t.default(e);return{...e,getKey:n}}function n(e,t){var n;const{getKey:o,init:u}=r(t);return e.reduce(((e,t,r,n)=>{var u;const l=o(t,r,n);return null!==(u=e[l])&&void 0!==u||(e[l]=[]),e[l].push(t),e}),null!==(n=null==u?void 0:u())&&void 0!==n?n:{})}exports.arrayGroupToMap=function(e,t){var n;const{getKey:o,init:u}=r(t);return e.reduce(((e,t,r,n)=>{var u;const l=o(t,r,n),i=null!==(u=e.get(l))&&void 0!==u?u:[];return i.push(t),e.set(l,i),e}),null!==(n=null==u?void 0:u())&&void 0!==n?n:new Map)},exports.arrayGroupToRecord=n,exports.default=n,exports.handleOptions=r,exports.sumGroup=function(e){let t=0;return void 0===e.forEach&&(e=Object.values(e)),e.forEach((e=>t+=e.length)),t}; | ||
| //# sourceMappingURL=index.cjs.production.min.js.map |
| {"version":3,"file":"index.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["import hashSum from 'hash-sum';\n\nexport interface IOptionsForRecord<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): string\n\n\tinit?(): Record<string, T[]>,\n}\n\nexport interface IOptionsForMap<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): any\n\n\tinit?(): Map<any, T[]>,\n}\n\nexport function handleOptions<O extends IOptionsForRecord<any> | IOptionsForMap<any>>(options: O): O\n{\n\tconst getKey = options?.getKey ?? ((item) => hashSum(item));\n\n\treturn {\n\t\t...options,\n\t\tgetKey,\n\t}\n}\n\nexport function arrayGroupToRecord<T>(arr: T[], options?: IOptionsForRecord<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tmap[id] ??= [];\n\t\tmap[id].push(item);\n\n\t\treturn map\n\t}, init?.() ?? {} as Record<string, T[]>);\n}\n\nexport function arrayGroupToMap<T>(arr: T[], options?: IOptionsForMap<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tconst a = map.get(id) ?? [];\n\n\t\ta.push(item);\n\n\t\tmap.set(id, a);\n\n\t\treturn map\n\t}, init?.() ?? new Map() as Map<any, T[]>);\n}\n\nexport function sumGroup<T extends Record<any, any[]> | Map<any, any[]>>(group: T)\n{\n\tlet len = 0;\n\n\tif (typeof group.forEach === 'undefined')\n\t{\n\t\t// @ts-ignore\n\t\tgroup = Object.values(group);\n\t}\n\n\t// @ts-ignore\n\tgroup.forEach(b => len += b.length);\n\n\treturn len;\n}\n\nexport default arrayGroupToRecord\n"],"names":["handleOptions","options","getKey","item","hashSum","arrayGroupToRecord","arr","init","reduce","map","index","id","push","a","get","set","Map","group","len","forEach","Object","values","b","length"],"mappings":"kLAgBgBA,EAAsEC,eAE/EC,YAASD,MAAAA,SAAAA,EAASC,sBAAYC,GAASC,UAAQD,SAE9C,IACHF,EACHC,OAAAA,YAIcG,EAAsBC,EAAUL,eAEzCC,OAAEA,EAAFK,KAAUA,GAASP,EAAcC,UAEhCK,EAAIE,QAAO,CAACC,EAAKN,EAAMO,EAAOJ,iBAG9BK,EAAKT,EAAOC,EAAMO,EAAOJ,oBAE/BG,EAAIE,kBAAJF,EAAIE,GAAQ,IACZF,EAAIE,GAAIC,KAAKT,GAENM,cACLF,MAAAA,SAAAA,mBAAY,qCAGmBD,EAAUL,eAEtCC,OAAEA,EAAFK,KAAUA,GAASP,EAAcC,UAEhCK,EAAIE,QAAO,CAACC,EAAKN,EAAMO,EAAOJ,iBAG9BK,EAAKT,EAAOC,EAAMO,EAAOJ,GAEzBO,YAAIJ,EAAIK,IAAIH,kBAAO,UAEzBE,EAAED,KAAKT,GAEPM,EAAIM,IAAIJ,EAAIE,GAELJ,cACLF,MAAAA,SAAAA,mBAAY,IAAIS,uGAGqDC,OAEpEC,EAAM,cAEmB,IAAlBD,EAAME,UAGhBF,EAAQG,OAAOC,OAAOJ,IAIvBA,EAAME,SAAQG,GAAKJ,GAAOI,EAAEC,SAErBL"} |
| import hashSum from 'hash-sum'; | ||
| function handleOptions(options) { | ||
| var _options$getKey; | ||
| const getKey = (_options$getKey = options === null || options === void 0 ? void 0 : options.getKey) !== null && _options$getKey !== void 0 ? _options$getKey : item => hashSum(item); | ||
| return { ...options, | ||
| getKey | ||
| }; | ||
| } | ||
| function arrayGroupToRecord(arr, options) { | ||
| var _init; | ||
| const { | ||
| getKey, | ||
| init | ||
| } = handleOptions(options); | ||
| return arr.reduce((map, item, index, arr) => { | ||
| var _map$id; | ||
| const id = getKey(item, index, arr); | ||
| (_map$id = map[id]) !== null && _map$id !== void 0 ? _map$id : map[id] = []; | ||
| map[id].push(item); | ||
| return map; | ||
| }, (_init = init === null || init === void 0 ? void 0 : init()) !== null && _init !== void 0 ? _init : {}); | ||
| } | ||
| function arrayGroupToMap(arr, options) { | ||
| var _init2; | ||
| const { | ||
| getKey, | ||
| init | ||
| } = handleOptions(options); | ||
| return arr.reduce((map, item, index, arr) => { | ||
| var _map$get; | ||
| const id = getKey(item, index, arr); | ||
| const a = (_map$get = map.get(id)) !== null && _map$get !== void 0 ? _map$get : []; | ||
| a.push(item); | ||
| map.set(id, a); | ||
| return map; | ||
| }, (_init2 = init === null || init === void 0 ? void 0 : init()) !== null && _init2 !== void 0 ? _init2 : new Map()); | ||
| } | ||
| function sumGroup(group) { | ||
| let len = 0; | ||
| if (typeof group.forEach === 'undefined') { | ||
| group = Object.values(group); | ||
| } | ||
| group.forEach(b => len += b.length); | ||
| return len; | ||
| } | ||
| export { arrayGroupToMap, arrayGroupToRecord, arrayGroupToRecord as default, handleOptions, sumGroup }; | ||
| //# sourceMappingURL=index.esm.js.map |
| {"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["import hashSum from 'hash-sum';\n\nexport interface IOptionsForRecord<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): string\n\n\tinit?(): Record<string, T[]>,\n}\n\nexport interface IOptionsForMap<T>\n{\n\tgetKey?(item: T, index: number, arr: T[]): any\n\n\tinit?(): Map<any, T[]>,\n}\n\nexport function handleOptions<O extends IOptionsForRecord<any> | IOptionsForMap<any>>(options: O): O\n{\n\tconst getKey = options?.getKey ?? ((item) => hashSum(item));\n\n\treturn {\n\t\t...options,\n\t\tgetKey,\n\t}\n}\n\nexport function arrayGroupToRecord<T>(arr: T[], options?: IOptionsForRecord<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tmap[id] ??= [];\n\t\tmap[id].push(item);\n\n\t\treturn map\n\t}, init?.() ?? {} as Record<string, T[]>);\n}\n\nexport function arrayGroupToMap<T>(arr: T[], options?: IOptionsForMap<T>)\n{\n\tconst { getKey, init } = handleOptions(options);\n\n\treturn arr.reduce((map, item, index, arr) =>\n\t{\n\n\t\tconst id = getKey(item, index, arr);\n\n\t\tconst a = map.get(id) ?? [];\n\n\t\ta.push(item);\n\n\t\tmap.set(id, a);\n\n\t\treturn map\n\t}, init?.() ?? new Map() as Map<any, T[]>);\n}\n\nexport function sumGroup<T extends Record<any, any[]> | Map<any, any[]>>(group: T)\n{\n\tlet len = 0;\n\n\tif (typeof group.forEach === 'undefined')\n\t{\n\t\t// @ts-ignore\n\t\tgroup = Object.values(group);\n\t}\n\n\t// @ts-ignore\n\tgroup.forEach(b => len += b.length);\n\n\treturn len;\n}\n\nexport default arrayGroupToRecord\n"],"names":["handleOptions","options","getKey","item","hashSum","arrayGroupToRecord","arr","init","reduce","map","index","id","push","arrayGroupToMap","a","get","set","Map","sumGroup","group","len","forEach","Object","values","b","length"],"mappings":";;SAgBgBA,cAAsEC;;;AAErF,QAAMC,MAAM,sBAAGD,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEC,MAAZ,6DAAwBC,IAAD,IAAUC,OAAO,CAACD,IAAD,CAApD;AAEA,SAAO,EACN,GAAGF,OADG;AAENC,IAAAA;AAFM,GAAP;AAIA;SAEeG,mBAAsBC,KAAUL;;;AAE/C,QAAM;AAAEC,IAAAA,MAAF;AAAUK,IAAAA;AAAV,MAAmBP,aAAa,CAACC,OAAD,CAAtC;AAEA,SAAOK,GAAG,CAACE,MAAJ,CAAW,CAACC,GAAD,EAAMN,IAAN,EAAYO,KAAZ,EAAmBJ,GAAnB;;;AAGjB,UAAMK,EAAE,GAAGT,MAAM,CAACC,IAAD,EAAOO,KAAP,EAAcJ,GAAd,CAAjB;AAEA,eAAAG,GAAG,CAACE,EAAD,CAAH,6CAAAF,GAAG,CAACE,EAAD,CAAH,GAAY,EAAZ;AACAF,IAAAA,GAAG,CAACE,EAAD,CAAH,CAAQC,IAAR,CAAaT,IAAb;AAEA,WAAOM,GAAP;AACA,GATM,WASJF,IATI,aASJA,IATI,uBASJA,IAAI,EATA,yCASQ,EATR,CAAP;AAUA;SAEeM,gBAAmBP,KAAUL;;;AAE5C,QAAM;AAAEC,IAAAA,MAAF;AAAUK,IAAAA;AAAV,MAAmBP,aAAa,CAACC,OAAD,CAAtC;AAEA,SAAOK,GAAG,CAACE,MAAJ,CAAW,CAACC,GAAD,EAAMN,IAAN,EAAYO,KAAZ,EAAmBJ,GAAnB;;;AAGjB,UAAMK,EAAE,GAAGT,MAAM,CAACC,IAAD,EAAOO,KAAP,EAAcJ,GAAd,CAAjB;AAEA,UAAMQ,CAAC,eAAGL,GAAG,CAACM,GAAJ,CAAQJ,EAAR,CAAH,+CAAkB,EAAzB;AAEAG,IAAAA,CAAC,CAACF,IAAF,CAAOT,IAAP;AAEAM,IAAAA,GAAG,CAACO,GAAJ,CAAQL,EAAR,EAAYG,CAAZ;AAEA,WAAOL,GAAP;AACA,GAZM,YAYJF,IAZI,aAYJA,IAZI,uBAYJA,IAAI,EAZA,2CAYQ,IAAIU,GAAJ,EAZR,CAAP;AAaA;SAEeC,SAAyDC;AAExE,MAAIC,GAAG,GAAG,CAAV;;AAEA,MAAI,OAAOD,KAAK,CAACE,OAAb,KAAyB,WAA7B,EACA;AAECF,IAAAA,KAAK,GAAGG,MAAM,CAACC,MAAP,CAAcJ,KAAd,CAAR;AACA;;AAGDA,EAAAA,KAAK,CAACE,OAAN,CAAcG,CAAC,IAAIJ,GAAG,IAAII,CAAC,CAACC,MAA5B;AAEA,SAAOL,GAAP;AACA;;;;"} |
| 'use strict' | ||
| if (process.env.NODE_ENV === 'production') { | ||
| module.exports = require('./index.cjs.production.min.js') | ||
| } else { | ||
| module.exports = require('./index.cjs.development.js') | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
29014
68.34%15
36.36%180
41.73%2
100%1
Infinity%Updated