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

Method _replaceAllString

src/MagicString.js:886–903  ·  view source on GitHub ↗
(string, replacement)

Source from the content-addressed store, hash-verified

884 }
885
886 _replaceAllString(string, replacement) {
887 const { original } = this;
888 const stringLength = string.length;
889 for (
890 let index = original.indexOf(string);
891 index !== -1;
892 index = original.indexOf(string, index + stringLength)
893 ) {
894 const previous = original.slice(index, index + stringLength);
895 let _replacement = replacement;
896 if (typeof replacement === 'function') {
897 _replacement = replacement(previous, index, original);
898 }
899 if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
900 }
901
902 return this;
903 }
904
905 replaceAll(searchValue, replacement) {
906 if (typeof searchValue === 'string') {

Callers 1

replaceAllMethod · 0.95

Calls 2

overwriteMethod · 0.95
sliceMethod · 0.45

Tested by

no test coverage detected