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

Method _replaceAllString

src/MagicString.ts:1216–1232  ·  view source on GitHub ↗

@internal

(string: string, replacement: string | ReplacementFunction)

Source from the content-addressed store, hash-verified

1214
1215 /** @internal */
1216 _replaceAllString(string: string, replacement: string | ReplacementFunction): this {
1217 const { original } = this
1218 const stringLength = string.length
1219 for (
1220 let index = original.indexOf(string);
1221 index !== -1;
1222 index = original.indexOf(string, index + stringLength)
1223 ) {
1224 const previous = original.slice(index, index + stringLength)
1225 const _replacement
1226 = typeof replacement === 'function' ? replacement(previous, index, original) : replacement
1227 if (previous !== _replacement)
1228 this.overwrite(index, index + stringLength, _replacement)
1229 }
1230
1231 return this
1232 }
1233
1234 /**
1235 * Same as `s.replace`, but replace all matched strings instead of just one.

Callers 1

replaceAllMethod · 0.95

Calls 2

overwriteMethod · 0.95
sliceMethod · 0.45

Tested by

no test coverage detected