The string value to search and replace within.
The value to search for. Can be a string, a global RegExp, or any object
with a [Symbol.replace] method.
The replacement string (may use $&, $1…$n, $\`` and $'` patterns)
or a replacer function called once per match.
A new string with every occurrence of searchValue replaced by replaceValue.
Polyfill implementation of
String.prototype.replaceAll()that returns a new string with all matches of a pattern replaced by a replacement.Matches the behaviour of the native
String.prototype.replaceAll()method:RegExpsearchValuemust carry the global (g) flag; a non-globalRegExpthrows aTypeError.searchValueis treated as a literal pattern (special regex characters are escaped) and all occurrences are replaced.searchValueexposes a[Symbol.replace]method, that method is called with the coerced string value andreplaceValue, mirroring the native delegation behaviour.replaceValueis a function it is invoked for each match with the matched substring, captured groups, the match index, and the original string.