{"version":3,"file":"countBy.mjs","names":[],"sources":["../../src/collection/countBy.ts"],"sourcesContent":["/**\n * Creates an object composed from the elements of collection grouped by the results of running each element thru iteratee, with counts\n * @param collection - The collection to iterate over\n * @param iteratee - The iteratee to transform keys\n * @returns Returns the composed aggregate object with counts\n * @example\n * const users = [\n *   { name: 'John', age: 30 },\n *   { name: 'Jane', age: 30 },\n *   { name: 'Bob', age: 25 }\n * ];\n * countBy(users, 'age');\n * // => { '30': 2, '25': 1 }\n */\nexport function countBy<T>(\n  collection: T[],\n  iteratee: ((item: T, index: number) => string | number) | string,\n): Record<string | number, number> {\n  const result: Record<string | number, number> = {};\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    result[key] = (result[key] || 0) + 1;\n  });\n\n  return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAgB,QACd,YACA,UACiC;CACjC,MAAM,SAA0C,CAAC;CAEjD,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,OAAO,QAAQ,OAAO,QAAQ,KAAK;CACrC,CAAC;CAED,OAAO;AACT"}