From e24c92918e1f2358f6c12c840f636c092d5bf41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20J=C3=A4derberg?= Date: Mon, 29 Sep 2025 06:58:31 +0000 Subject: [PATCH] Merged in fix/BOOK-398-polyfill-at (pull request #2876) Fix/BOOK-398 polyfill at * fix(BOOK-398): Add polyfills for .at() * fix(BOOK-398): Add polyfills for .at() Approved-by: Linus Flood --- apps/partner-sas/app/layout.tsx | 2 ++ apps/scandic-web/app/[lang]/(live)/layout.tsx | 1 + .../app/[lang]/(no-layout)/layout.tsx | 1 + .../app/[lang]/(partner)/layout.tsx | 1 + .../scandic-web/app/[lang]/webview/layout.tsx | 1 + packages/common/package.json | 1 + packages/common/polyfills/at.ts | 26 +++++++++++++++++++ packages/common/polyfills/index.ts | 3 +++ 8 files changed, 36 insertions(+) create mode 100644 packages/common/polyfills/at.ts create mode 100644 packages/common/polyfills/index.ts diff --git a/apps/partner-sas/app/layout.tsx b/apps/partner-sas/app/layout.tsx index f19baa541..c97bcf061 100644 --- a/apps/partner-sas/app/layout.tsx +++ b/apps/partner-sas/app/layout.tsx @@ -1,3 +1,5 @@ +import "@scandic-hotels/common/polyfills" + import { configureTrpc } from "@/lib/trpc" configureTrpc() diff --git a/apps/scandic-web/app/[lang]/(live)/layout.tsx b/apps/scandic-web/app/[lang]/(live)/layout.tsx index 516e96c97..46daebf73 100644 --- a/apps/scandic-web/app/[lang]/(live)/layout.tsx +++ b/apps/scandic-web/app/[lang]/(live)/layout.tsx @@ -3,6 +3,7 @@ import "@scandic-hotels/design-system/normalize.css" import "@/app/globals.css" import "@scandic-hotels/design-system/design-system-new-deprecated.css" import "@scandic-hotels/design-system/style.css" +import "@scandic-hotels/common/polyfills" import { ReactQueryDevtools } from "@tanstack/react-query-devtools" import Script from "next/script" diff --git a/apps/scandic-web/app/[lang]/(no-layout)/layout.tsx b/apps/scandic-web/app/[lang]/(no-layout)/layout.tsx index 4e09effd0..f063321a7 100644 --- a/apps/scandic-web/app/[lang]/(no-layout)/layout.tsx +++ b/apps/scandic-web/app/[lang]/(no-layout)/layout.tsx @@ -3,6 +3,7 @@ import "@scandic-hotels/design-system/normalize.css" import "@/app/globals.css" import "@scandic-hotels/design-system/design-system-new-deprecated.css" import "@scandic-hotels/design-system/style.css" +import "@scandic-hotels/common/polyfills" import { ReactQueryDevtools } from "@tanstack/react-query-devtools" import Script from "next/script" diff --git a/apps/scandic-web/app/[lang]/(partner)/layout.tsx b/apps/scandic-web/app/[lang]/(partner)/layout.tsx index 77115835c..4b0c3911a 100644 --- a/apps/scandic-web/app/[lang]/(partner)/layout.tsx +++ b/apps/scandic-web/app/[lang]/(partner)/layout.tsx @@ -3,6 +3,7 @@ import "@scandic-hotels/design-system/normalize.css" import "@/app/globals.css" import "@scandic-hotels/design-system/design-system-new-deprecated.css" import "@scandic-hotels/design-system/style.css" +import "@scandic-hotels/common/polyfills" import { ReactQueryDevtools } from "@tanstack/react-query-devtools" import Script from "next/script" diff --git a/apps/scandic-web/app/[lang]/webview/layout.tsx b/apps/scandic-web/app/[lang]/webview/layout.tsx index 6be312399..15beb5733 100644 --- a/apps/scandic-web/app/[lang]/webview/layout.tsx +++ b/apps/scandic-web/app/[lang]/webview/layout.tsx @@ -3,6 +3,7 @@ import "@scandic-hotels/design-system/normalize.css" import "@/app/globals.css" import "@scandic-hotels/design-system/style.css" import "@scandic-hotels/design-system/design-system-new-deprecated.css" +import "@scandic-hotels/common/polyfills" import Script from "next/script" diff --git a/packages/common/package.json b/packages/common/package.json index 5b394d44f..5c08590b9 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -11,6 +11,7 @@ "lint": "eslint . --max-warnings 0 && tsc --noEmit" }, "exports": { + "./polyfills": "./polyfills/index.ts", "./constants/alert": "./constants/alert.ts", "./constants/booking": "./constants/booking.ts", "./constants/currency": "./constants/currency.ts", diff --git a/packages/common/polyfills/at.ts b/packages/common/polyfills/at.ts new file mode 100644 index 000000000..1c9b811ff --- /dev/null +++ b/packages/common/polyfills/at.ts @@ -0,0 +1,26 @@ +if (!Array.prototype.at) { + Array.prototype.at = function (index: number) { + // Convert the index to an integer + index = Math.trunc(index) || 0 + if (index < 0) { + index += this.length + } + if (index < 0 || index >= this.length) { + return undefined + } + return this[index] + } +} + +if (!String.prototype.at) { + String.prototype.at = function (index: number) { + index = Math.trunc(index) || 0 + if (index < 0) { + index += this.length + } + if (index < 0 || index >= this.length) { + return undefined + } + return this.charAt(index) + } +} diff --git a/packages/common/polyfills/index.ts b/packages/common/polyfills/index.ts new file mode 100644 index 000000000..21a9accda --- /dev/null +++ b/packages/common/polyfills/index.ts @@ -0,0 +1,3 @@ +"use client" + +import "./at"