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

Method _replaceAllString

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

@internal

(string: string, replacement: string | ReplacementFunction)

Source from the content-addressed store, hash-verified

1198
1199 /** @internal */
1200 _replaceAllString(string: string, replacement: string | ReplacementFunction): this {
1201 const { original } = this
1202 const stringLength = string.length
1203 for (
1204 let index = original.indexOf(string);
1205 index !== -1;
1206 index = original.indexOf(string, index + stringLength)
1207 ) {
1208 const previous = original.slice(index, index + stringLength)
1209 const _replacement
1210 = typeof replacement === 'function' ? replacement(previous, index, original) : replacement
1211 if (previous !== _replacement)
1212 this.overwrite(index, index + stringLength, _replacement)
1213 }
1214
1215 return this
1216 }
1217
1218 /**
1219 * 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