{"version":3,"file":"keyBy.mjs","names":[],"sources":["../../src/collection/keyBy.ts"],"sourcesContent":["/**\n * Creates an object composed from the elements of collection keyed 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 *   { id: 1, name: 'John' },\n *   { id: 2, name: 'Jane' }\n * ];\n * keyBy(users, 'id');\n * // => { '1': {id: 1, name: 'John'}, '2': {id: 2, name: 'Jane'} }\n */\nexport function keyBy<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 'id'\n      key = (item as Record<string, unknown>)[iteratee] as string | number;\n    } else {\n      key = String(item);\n    }\n\n    result[key] = item;\n  });\n\n  return result;\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,MACd,YACA,UAC4B;CAC5B,MAAM,SAAqC,CAAC;CAE5C,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,OAAO;CAChB,CAAC;CAED,OAAO;AACT"}