diff --git a/src/hooks.ts b/src/hooks.ts index a1454ac0..a3a5a34e 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -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 = ( + items: Iterable, + keySelector: (item: T, index: number) => K, + ): Partial> => { + return Array.from(items).reduce((acc: Partial>, ...args) => { + const key = keySelector(args[0], args[1]); + acc[key] ??= []; + acc[key].push(args[0]); + return acc; + }, {}); + }; +}