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"