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

Method _replaceString

src/MagicString.ts:1214–1228  ·  view source on GitHub ↗

@internal

(string: string, replacement: string | ReplacementFunction)

Source from the content-addressed store, hash-verified

1212
1213 /** @internal */
1214 _replaceString(string: string, replacement: string | ReplacementFunction): this {
1215 const { original } = this
1216 const index = original.indexOf(string)
1217
1218 if (index !== -1) {
1219 if (typeof replacement === 'function') {
1220 replacement = replacement(string, index, original)
1221 }
1222 if (string !== replacement) {
1223 this.overwrite(index, index + string.length, replacement)
1224 }
1225 }
1226
1227 return this
1228 }
1229
1230 /**
1231 * String replacement with RegExp or string.

Callers 1

replaceMethod · 0.95

Calls 1

overwriteMethod · 0.95

Tested by

no test coverage detected