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

Method _replaceString

src/MagicString.ts:1252–1266  ·  view source on GitHub ↗

@internal

(string: string, replacement: string | ReplacementFunction)

Source from the content-addressed store, hash-verified

1250
1251 /** @internal */
1252 _replaceString(string: string, replacement: string | ReplacementFunction): this {
1253 const { original } = this
1254 const index = original.indexOf(string)
1255
1256 if (index !== -1) {
1257 if (typeof replacement === 'function') {
1258 replacement = replacement(string, index, original)
1259 }
1260 if (string !== replacement) {
1261 this.overwrite(index, index + string.length, replacement)
1262 }
1263 }
1264
1265 return this
1266 }
1267
1268 /**
1269 * String replacement with RegExp or string.

Callers 1

replaceMethod · 0.95

Calls 1

overwriteMethod · 0.95

Tested by

no test coverage detected