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

Method replaceAll

src/MagicString.ts:1220–1232  ·  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

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

Callers 1

Calls 2

_replaceAllStringMethod · 0.95
_replaceRegexpMethod · 0.95

Tested by

no test coverage detected