{"version":3,"file":"groupBy.cjs","names":["isFunction","isUnsafeKey"],"sources":["../../src/array/groupBy.ts"],"sourcesContent":["import isUnsafeKey from '../object/isUnsafeKey';\nimport isFunction from '../types/isFunction';\n\n/**\n * Creates an object composed of keys generated from the results of running each element of collection through iteratee.\n *\n * Keys of `__proto__`, `constructor` and `prototype` are refused and their\n * elements dropped, as writing one would reach the prototype of the result.\n *\n * @param {T[]} arr The source array.\n * @param {Function|string} key The iteratee to transform keys.\n * @returns {Record<string, T[]>} The composed aggregate object.\n *\n * @example\n * groupBy([6.1, 4.2, 6.3], Math.floor) //=> { '4': [4.2], '6': [6.1, 6.3] }\n */\nexport default function groupBy<T>(\n  arr: T[],\n  key: ((val: T, index: number, arr: T[]) => string) | string,\n): Record<string, T[]> {\n  return arr.reduce((acc: Record<string, T[]>, obj, index, array) => {\n    const k = String(\n      isFunction(key) ? key(obj, index, array) : obj[key as keyof T],\n    );\n    if (isUnsafeKey(k)) {\n      return acc;\n    }\n\n    if (!acc[k]) {\n      acc[k] = [];\n    }\n    acc[k].push(obj);\n    return acc;\n  }, {});\n}\n"],"mappings":"iLAgBA,SAAwB,EACtB,EACA,EACqB,CACrB,OAAO,EAAI,QAAQ,EAA0B,EAAK,EAAO,IAAU,CACjE,IAAM,EAAI,OACRA,EAAAA,QAAW,CAAG,EAAI,EAAI,EAAK,EAAO,CAAK,EAAI,EAAI,EACjD,EASA,OARIC,EAAAA,QAAY,CAAC,EACR,GAGJ,EAAI,KACP,EAAI,GAAK,CAAC,GAEZ,EAAI,EAAE,CAAC,KAAK,CAAG,EACR,EACT,EAAG,CAAC,CAAC,CACP"}