DEV: Add polyfill for `String.prototype.replaceAll` (#16301)
This commit is contained in:
parent
720e1ca9e7
commit
c219740274
|
@ -1,9 +1,4 @@
|
||||||
if (
|
if (!window.WeakMap || !window.Promise || typeof globalThis === "undefined") {
|
||||||
!window.WeakMap ||
|
|
||||||
!window.Promise ||
|
|
||||||
typeof globalThis === "undefined" ||
|
|
||||||
!String.prototype.replaceAll
|
|
||||||
) {
|
|
||||||
window.unsupportedBrowser = true;
|
window.unsupportedBrowser = true;
|
||||||
} else {
|
} else {
|
||||||
// Some implementations of `WeakMap.prototype.has` do not accept false
|
// Some implementations of `WeakMap.prototype.has` do not accept false
|
||||||
|
|
|
@ -1,5 +1,27 @@
|
||||||
/* eslint-disable */
|
/* 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
|
// Needed for Safari 15.2 and below
|
||||||
// from: https://github.com/iamdustan/smoothscroll
|
// from: https://github.com/iamdustan/smoothscroll
|
||||||
(function () {
|
(function () {
|
||||||
|
|
Loading…
Reference in New Issue