{"version":3,"sources":["../../src/utils/map.ts"],"sourcesContent":["import type { PropertyOrFunction } from '../types';\r\n\r\nconst getKey = <T extends Record<string, any>>(\r\n  item: T,\r\n  property: PropertyOrFunction<T>,\r\n): string => {\r\n  return typeof property === 'function' ? property(item) : item[property];\r\n};\r\n\r\nexport const keyBy = <T extends Record<string, any>>(\r\n  ar: T[],\r\n  property: PropertyOrFunction<T>,\r\n): Record<string, T> => {\r\n  return (ar || []).reduce(\r\n    (accumulator, item) => {\r\n      const key = getKey(item, property);\r\n      /* eslint-disable functional/immutable-data */\r\n      accumulator[key] = item;\r\n      /* eslint-enable functional/immutable-data */\r\n      return accumulator;\r\n    },\r\n    {} as Record<string, T>,\r\n  );\r\n};\r\n\r\nexport const groupBy = <T extends Record<string, any>>(\r\n  ar: T[],\r\n  property: PropertyOrFunction<T>,\r\n): Record<string, T[]> => {\r\n  return (ar || []).reduce(\r\n    (accumulator, item) => {\r\n      const key = getKey(item, property);\r\n      /* eslint-disable functional/immutable-data */\r\n      accumulator[key] = accumulator[key] || [];\r\n      (accumulator[key] as T[]).push(item);\r\n      /* eslint-enable functional/immutable-data */\r\n      return accumulator;\r\n    },\r\n    {} as Record<string, T[]>,\r\n  );\r\n};\r\n"],"mappings":";AAEA,IAAM,SAAS,CACb,MACA,aACW;AACX,SAAO,OAAO,aAAa,aAAa,SAAS,IAAI,IAAI,KAAK,QAAQ;AACxE;AAEO,IAAM,QAAQ,CACnB,IACA,aACsB;AACtB,UAAQ,MAAM,CAAC,GAAG;AAAA,IAChB,CAAC,aAAa,SAAS;AACrB,YAAM,MAAM,OAAO,MAAM,QAAQ;AAEjC,kBAAY,GAAG,IAAI;AAEnB,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AAEO,IAAM,UAAU,CACrB,IACA,aACwB;AACxB,UAAQ,MAAM,CAAC,GAAG;AAAA,IAChB,CAAC,aAAa,SAAS;AACrB,YAAM,MAAM,OAAO,MAAM,QAAQ;AAEjC,kBAAY,GAAG,IAAI,YAAY,GAAG,KAAK,CAAC;AACxC,MAAC,YAAY,GAAG,EAAU,KAAK,IAAI;AAEnC,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;","names":[]}