MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / replaceAll

Method replaceAll

src/MagicString.ts:1221–1233  ·  view source on GitHub ↗

* Same as `s.replace`, but replace all matched strings instead of just one.

(searchValue: string | RegExp, replacement: string | ReplacementFunction)

Source from the content-addressed store, hash-verified

1219 * Same as `s.replace`, but replace all matched strings instead of just one.
1220 */
1221 replaceAll(searchValue: string | RegExp, replacement: string | ReplacementFunction): this {
1222 if (typeof searchValue === 'string') {
1223 return this._replaceAllString(searchValue, replacement)
1224 }
1225
1226 if (!searchValue.global) {
1227 throw new TypeError(
1228 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
1229 )
1230 }
1231
1232 return this._replaceRegexp(searchValue, replacement)
1233 }
1234}

Callers 1

Calls 2

_replaceAllStringMethod · 0.95
_replaceRegexpMethod · 0.95

Tested by

no test coverage detected