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

Method _replaceString

src/MagicString.ts:1171–1185  ·  view source on GitHub ↗

@internal

(string: string, replacement: string | ReplacementFunction)

Source from the content-addressed store, hash-verified

1169
1170 /** @internal */
1171 _replaceString(string: string, replacement: string | ReplacementFunction): this {
1172 const { original } = this
1173 const index = original.indexOf(string)
1174
1175 if (index !== -1) {
1176 if (typeof replacement === 'function') {
1177 replacement = replacement(string, index, original)
1178 }
1179 if (string !== replacement) {
1180 this.overwrite(index, index + string.length, replacement)
1181 }
1182 }
1183
1184 return this
1185 }
1186
1187 /**
1188 * String replacement with RegExp or string.

Callers 1

replaceMethod · 0.95

Calls 1

overwriteMethod · 0.95

Tested by

no test coverage detected