Skip to content

Commit

Permalink
Added polyfill for Object.groupBy (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fiery-132 authored Feb 17, 2025
1 parent cd490da commit 2b32352
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@ import "./dayjs-plugins";

import { i18n } from "$lib/utils/i18n";
export const reroute = i18n.reroute();

// Polyfill Object.groupBy
if (typeof Object.groupBy === typeof undefined) {
Object.groupBy = <K extends PropertyKey, T>(
items: Iterable<T>,
keySelector: (item: T, index: number) => K,
): Partial<Record<K, T[]>> => {
return Array.from(items).reduce((acc: Partial<Record<K, T[]>>, ...args) => {
const key = keySelector(args[0], args[1]);
acc[key] ??= [];
acc[key].push(args[0]);
return acc;
}, {});
};
}

0 comments on commit 2b32352

Please sign in to comment.