{"version":3,"file":"groupBy.cjs","names":[],"sources":["../../src/collection/groupBy.ts"],"sourcesContent":["/**\n * Creates an object composed from the elements of collection grouped by the results of running each element thru iteratee\n * @param collection - The collection to iterate over\n * @param iteratee - The iteratee to transform keys\n * @returns Returns the composed aggregate object\n * @example\n * const users = [\n *   { name: 'John', age: 30 },\n *   { name: 'Jane', age: 30 },\n *   { name: 'Bob', age: 25 }\n * ];\n * groupBy(users, 'age');\n * // => { '30': [{name: 'John', age: 30}, {name: 'Jane', age: 30}], '25': [{name: 'Bob', age: 25}] }\n */\nexport function groupBy<T>(\n  collection: T[],\n  iteratee: ((item: T, index: number) => string | number) | string,\n): Record<string | number, T[]> {\n  const result: Record<string | number, T[]> = {};\n\n  collection.forEach((item, index) => {\n    let key: string | number;\n\n    if (typeof iteratee === 'function') {\n      key = iteratee(item, index);\n    } else if (typeof iteratee === 'string') {\n      // Handle property access like 'age'\n      key = (item as Record<string, unknown>)[iteratee] as string | number;\n    } else {\n      key = String(item);\n    }\n\n    if (!result[key]) {\n      result[key] = [];\n    }\n    result[key].push(item);\n  });\n\n  return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,SAAgB,QACd,YACA,UAC8B;CAC9B,MAAM,SAAuC,CAAC;CAE9C,WAAW,SAAS,MAAM,UAAU;EAClC,IAAI;EAEJ,IAAI,OAAO,aAAa,YACtB,MAAM,SAAS,MAAM,KAAK;OACrB,IAAI,OAAO,aAAa,UAE7B,MAAO,KAAiC;OAExC,MAAM,OAAO,IAAI;EAGnB,IAAI,CAAC,OAAO,MACV,OAAO,OAAO,CAAC;EAEjB,OAAO,IAAI,CAAC,KAAK,IAAI;CACvB,CAAC;CAED,OAAO;AACT"}