{"version":3,"file":"index.cjs","sources":[""],"sourcesContent":["export type TGetGroupedByArgs = Parameters<typeof getGroupedBy>;\n\nexport type TGetGroupedByReturn = ReturnType<typeof getGroupedBy>;\n\n/**\n * Groups array items by a key returned from a selector.\n * @template T,TKey\n * @param {T[]} arr Source array\n * @param {(value: T, index: number, array: T[]) => TKey} getKey Group key selector\n * @returns {Partial<Record<TKey, T[]>>} Null-prototype object containing grouped items\n * @throws {TypeError} getGroupedBy: arr must be an array\n * @throws {TypeError} getGroupedBy: getKey must be a function\n * @example\n * getGroupedBy([ { type: \"a\" }, { type: \"b\" } ], (item) => item.type);\n * @example\n * // Group orders by status before rendering dashboard columns\n * const ordersByStatus = getGroupedBy(orders, (order) => order.status);\n * const pendingOrders = ordersByStatus.pending ?? [];\n */\nexport const getGroupedBy = <T, TKey extends PropertyKey>(\n  arr: T[],\n  getKey: (value: T, index: number, array: T[]) => TKey\n): Partial<Record<TKey, T[]>> => {\n  if (!Array.isArray(arr)) {\n    throw new TypeError(\"getGroupedBy: arr must be an array\");\n  }\n  if (typeof getKey !== \"function\") {\n    throw new TypeError(\"getGroupedBy: getKey must be a function\");\n  }\n\n  const result = Object.create(null) as Partial<Record<TKey, T[]>>;\n  arr.forEach((value, index, array) => {\n    const key = getKey(value, index, array);\n    const group = result[key];\n    if (group) {\n      group.push(value);\n    } else {\n      result[key] = [ value ];\n    }\n  });\n  return result;\n};\n"],"names":["getGroupedBy","arr","getKey","Array","isArray","TypeError","result","Object","create","forEach","value","index","array","key","group","push"],"mappings":"+DAmBaA,aAAe,CAC1BC,IACAC,UAEA,IAAKC,MAAMC,QAAQH,KACjB,MAAM,IAAII,UAAU,sCAEtB,UAAWH,SAAW,WACpB,MAAM,IAAIG,UAAU,2CAGtB,MAAMC,OAASC,OAAOC,OAAO,MAC7BP,IAAIQ,QAAQ,CAACC,MAAOC,MAAOC,SACzB,MAAMC,IAAMX,OAAOQ,MAAOC,MAAOC,OACjC,MAAME,MAAQR,OAAOO,KACrB,GAAIC,MACFA,MAAMC,KAAKL,YAEXJ,OAAOO,KAAO,CAAEH,SAGpB,OAAOJ"}