DEV: Add polyfill for `String.prototype.replaceAll` (#16301)
This commit is contained in:
parent
720e1ca9e7
commit
c219740274
|
@ -1,9 +1,4 @@
|
|||
if (
|
||||
!window.WeakMap ||
|
||||
!window.Promise ||
|
||||
typeof globalThis === "undefined" ||
|
||||
!String.prototype.replaceAll
|
||||
) {
|
||||
if (!window.WeakMap || !window.Promise || typeof globalThis === "undefined") {
|
||||
window.unsupportedBrowser = true;
|
||||
} else {
|
||||
// Some implementations of `WeakMap.prototype.has` do not accept false
|
||||
|
|
|
@ -1,5 +1,27 @@
|
|||
/* eslint-disable */
|
||||
|
||||
// Needed for iOS <= 13.3
|
||||
if (!String.prototype.replaceAll) {
|
||||
String.prototype.replaceAll = function (
|
||||
pattern,
|
||||
replacementStringOrFunction
|
||||
) {
|
||||
let regex;
|
||||
|
||||
if (
|
||||
Object.prototype.toString.call(pattern).toLowerCase() ===
|
||||
"[object regexp]"
|
||||
) {
|
||||
regex = pattern;
|
||||
} else {
|
||||
const escapedStr = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
regex = new RegExp(escapedStr, "g");
|
||||
}
|
||||
|
||||
return this.replace(regex, replacementStringOrFunction);
|
||||
};
|
||||
}
|
||||
|
||||
// Needed for Safari 15.2 and below
|
||||
// from: https://github.com/iamdustan/smoothscroll
|
||||
(function () {
|
||||
|
|
Loading…
Reference in New Issue