Skip to content

Commit 0ae0a04

Browse files
committed
Simplify the replaceAll polyfill setup
1 parent 9b9ea93 commit 0ae0a04

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"@radix-ui/react-tooltip": "^1.0.7",
3737
"@wyw-in-js/babel-preset": "^1.0.6",
3838
"@wyw-in-js/transform": "^1.0.6",
39-
"core-js": "^3.47.0",
4039
"date-fns": "^1.29.0",
4140
"fs-extra": "^6.0.0",
4241
"gray-matter": "^4.0.3",

src/components/elements/polyfills/index.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22

33
// Polyfill for older browsers (more common here than we'd expect, due to testing
44
// on old Android emulators etc):
5-
import 'core-js/actual/string/replace-all';
5+
if (!String.prototype.replaceAll) {
6+
String.prototype.replaceAll = function (
7+
this: string,
8+
search: string | RegExp,
9+
replacement: string | ((substring: string, ...args: unknown[]) => string),
10+
) {
11+
if (search instanceof RegExp) {
12+
if (!search.global) {
13+
throw new TypeError('String.prototype.replaceAll called with a non-global RegExp argument');
14+
}
15+
return this.replace(search, replacement as string);
16+
}
17+
return this.split(search).join(replacement as string);
18+
} as typeof String.prototype.replaceAll;
19+
}
620

721
export function Polyfills() {
822
return null;
9-
}
23+
}

0 commit comments

Comments
 (0)