{"version":3,"file":"get-unique.mjs","names":[],"sources":["../src/get-unique.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n                       🗲 Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website:                  https://stormsoftware.com\n Repository:               https://github.com/storm-software/stryke\n Documentation:            https://docs.stormsoftware.com/projects/stryke\n Contact:                  https://stormsoftware.com/contact\n\n SPDX-License-Identifier:  Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Returns an array of unique values from the given array.\n *\n * @param arr - The array to get unique values from.\n * @returns An array of unique values.\n */\nexport const getUnique = <T = any>(arr: T[]): T[] => {\n  return [...new Set(arr)];\n};\n\n/**\n * Returns a new array containing only the unique elements from the original array,\n * based on the values returned by the mapper function.\n *\n * @example\n * ```ts\n * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);\n * // [1.2, 2.1, 3.2, 5.7, 7.19]\n * ```\n *\n * @param arr - The array to process.\n * @param mapper - The function used to convert the array elements.\n * @returns A new array containing only the unique elements from the original array, based on the values returned by the mapper function.\n */\nexport function getUniqueBy<T, U>(\n  arr: readonly T[],\n  mapper: (item: T) => U = item => item as unknown as U\n): T[] {\n  const map = new Map<U, T>();\n\n  for (const item of arr) {\n    const key = mapper(item);\n\n    if (!map.has(key)) {\n      map.set(key, item);\n    }\n  }\n\n  return [...map.values()];\n}\n"],"mappings":";;;;;;;AAwBA,MAAa,aAAsB,QAAkB;AACnD,QAAO,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC;;;;;;;;;;;;;;;;AAiB1B,SAAgB,YACd,KACA,UAAyB,SAAQ,MAC5B;CACL,MAAM,sBAAM,IAAI,KAAW;AAE3B,MAAK,MAAM,QAAQ,KAAK;EACtB,MAAM,MAAM,OAAO,KAAK;AAExB,MAAI,CAAC,IAAI,IAAI,IAAI,CACf,KAAI,IAAI,KAAK,KAAK;;AAItB,QAAO,CAAC,GAAG,IAAI,QAAQ,CAAC"}