Skip to content

Commit 6ad20af

Browse files
committed
perf: use the efficient String#replaceAll when supported #95
1 parent 357d5b2 commit 6ad20af

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ export function getCaptured(input: string, re: RegExp): string[] {
9292
* A simplified version of `String.replaceAll` to address compatibility issues on Node 14
9393
*/
9494
export function replaceAll(source: string, searchValue: string, replaceValue: string): string {
95+
if (typeof source.replaceAll === 'function')
96+
return source.replaceAll(searchValue, replaceValue)
9597
const escaped = escapeStringRegexp(searchValue)
9698
const replaceRegExp = new RegExp(escaped, 'g')
9799
return source.replace(replaceRegExp, replaceValue)

0 commit comments

Comments
 (0)