From f0f6e69e501582f9847c122dbe62e291e62d6476 Mon Sep 17 00:00:00 2001 From: Simon Mechler <170467894+Fiery-132@users.noreply.github.com> Date: Mon, 17 Feb 2025 21:15:15 +0100 Subject: [PATCH] Added polyfill for Object.groupBy --- src/hooks.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/hooks.ts b/src/hooks.ts index a1454ac02..a3a5a34e6 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; + }, {}); + }; +}