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
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import "@scandic-hotels/common/polyfills"
|
||||||
|
|
||||||
import { configureTrpc } from "@/lib/trpc"
|
import { configureTrpc } from "@/lib/trpc"
|
||||||
|
|
||||||
configureTrpc()
|
configureTrpc()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import "@scandic-hotels/design-system/normalize.css"
|
|||||||
import "@/app/globals.css"
|
import "@/app/globals.css"
|
||||||
import "@scandic-hotels/design-system/design-system-new-deprecated.css"
|
import "@scandic-hotels/design-system/design-system-new-deprecated.css"
|
||||||
import "@scandic-hotels/design-system/style.css"
|
import "@scandic-hotels/design-system/style.css"
|
||||||
|
import "@scandic-hotels/common/polyfills"
|
||||||
|
|
||||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
|
||||||
import Script from "next/script"
|
import Script from "next/script"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import "@scandic-hotels/design-system/normalize.css"
|
|||||||
import "@/app/globals.css"
|
import "@/app/globals.css"
|
||||||
import "@scandic-hotels/design-system/design-system-new-deprecated.css"
|
import "@scandic-hotels/design-system/design-system-new-deprecated.css"
|
||||||
import "@scandic-hotels/design-system/style.css"
|
import "@scandic-hotels/design-system/style.css"
|
||||||
|
import "@scandic-hotels/common/polyfills"
|
||||||
|
|
||||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
|
||||||
import Script from "next/script"
|
import Script from "next/script"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import "@scandic-hotels/design-system/normalize.css"
|
|||||||
import "@/app/globals.css"
|
import "@/app/globals.css"
|
||||||
import "@scandic-hotels/design-system/design-system-new-deprecated.css"
|
import "@scandic-hotels/design-system/design-system-new-deprecated.css"
|
||||||
import "@scandic-hotels/design-system/style.css"
|
import "@scandic-hotels/design-system/style.css"
|
||||||
|
import "@scandic-hotels/common/polyfills"
|
||||||
|
|
||||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
|
||||||
import Script from "next/script"
|
import Script from "next/script"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import "@scandic-hotels/design-system/normalize.css"
|
|||||||
import "@/app/globals.css"
|
import "@/app/globals.css"
|
||||||
import "@scandic-hotels/design-system/style.css"
|
import "@scandic-hotels/design-system/style.css"
|
||||||
import "@scandic-hotels/design-system/design-system-new-deprecated.css"
|
import "@scandic-hotels/design-system/design-system-new-deprecated.css"
|
||||||
|
import "@scandic-hotels/common/polyfills"
|
||||||
|
|
||||||
import Script from "next/script"
|
import Script from "next/script"
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"lint": "eslint . --max-warnings 0 && tsc --noEmit"
|
"lint": "eslint . --max-warnings 0 && tsc --noEmit"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
|
"./polyfills": "./polyfills/index.ts",
|
||||||
"./constants/alert": "./constants/alert.ts",
|
"./constants/alert": "./constants/alert.ts",
|
||||||
"./constants/booking": "./constants/booking.ts",
|
"./constants/booking": "./constants/booking.ts",
|
||||||
"./constants/currency": "./constants/currency.ts",
|
"./constants/currency": "./constants/currency.ts",
|
||||||
|
|||||||
26
packages/common/polyfills/at.ts
Normal file
26
packages/common/polyfills/at.ts
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
3
packages/common/polyfills/index.ts
Normal file
3
packages/common/polyfills/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import "./at"
|
||||||
Reference in New Issue
Block a user