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

Method _replaceString

src/MagicString.ts:1188–1202  ·  view source on GitHub ↗

@internal

(string: string, replacement: string | ReplacementFunction)

Source from the content-addressed store, hash-verified

1186
1187 /** @internal */
1188 _replaceString(string: string, replacement: string | ReplacementFunction): this {
1189 const { original } = this
1190 const index = original.indexOf(string)
1191
1192 if (index !== -1) {
1193 if (typeof replacement === 'function') {
1194 replacement = replacement(string, index, original)
1195 }
1196 if (string !== replacement) {
1197 this.overwrite(index, index + string.length, replacement)
1198 }
1199 }
1200
1201 return this
1202 }
1203
1204 /**
1205 * String replacement with RegExp or string.

Callers 1

replaceMethod · 0.95

Calls 1

overwriteMethod · 0.95

Tested by

no test coverage detected