{"version":3,"file":"index.cjs","sources":[""],"sourcesContent":["export type TGetUniqueByArgs = Parameters<typeof getUniqueBy>;\n\nexport type TGetUniqueByReturn = ReturnType<typeof getUniqueBy>;\n\n/**\n * Returns the first item for every unique selector result.\n * @template T,TKey\n * @param {T[]} arr Source array\n * @param {(value: T, index: number, array: T[]) => TKey} getKey Unique key selector\n * @returns {T[]} New array containing unique items\n * @throws {TypeError} getUniqueBy: arr must be an array\n * @throws {TypeError} getUniqueBy: getKey must be a function\n * @example\n * getUniqueBy([ { id: 1 }, { id: 1 }, { id: 2 } ], (item) => item.id);\n * @example\n * // Remove duplicate products by SKU while preserving the first result\n * const uniqueProducts = getUniqueBy(products, (product) => product.sku);\n */\nexport const getUniqueBy = <T, TKey>(\n  arr: T[],\n  getKey: (value: T, index: number, array: T[]) => TKey\n): T[] => {\n  if (!Array.isArray(arr)) {\n    throw new TypeError(\"getUniqueBy: arr must be an array\");\n  }\n  if (typeof getKey !== \"function\") {\n    throw new TypeError(\"getUniqueBy: getKey must be a function\");\n  }\n\n  const keys = new Set<TKey>();\n  return arr.filter((value, index, array) => {\n    const key = getKey(value, index, array);\n    if (keys.has(key)) {\n      return false;\n    }\n    keys.add(key);\n    return true;\n  });\n};\n"],"names":["getUniqueBy","arr","getKey","Array","isArray","TypeError","keys","Set","filter","value","index","array","key","has","add"],"mappings":"+DAkBaA,YAAc,CACzBC,IACAC,UAEA,IAAKC,MAAMC,QAAQH,KACjB,MAAM,IAAII,UAAU,qCAEtB,UAAWH,SAAW,WACpB,MAAM,IAAIG,UAAU,0CAGtB,MAAMC,KAAO,IAAIC,IACjB,OAAON,IAAIO,OAAO,CAACC,MAAOC,MAAOC,SAC/B,MAAMC,IAAMV,OAAOO,MAAOC,MAAOC,OACjC,GAAIL,KAAKO,IAAID,KACX,OAAO,MAETN,KAAKQ,IAAIF,KACT,OAAO"}