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

Method getReplacement

benchmark/data.js:788–800  ·  view source on GitHub ↗
(match, str)

Source from the content-addressed store, hash-verified

786 }
787 replace(searchValue, replacement) {
788 function getReplacement(match, str) {
789 if (typeof replacement === 'string') {
790 return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
791 if (i === '$') return '$';
792 if (i === '&') return match[0];
793 const num = +i;
794 if (num < match.length) return match[+i];
795 return `$${i}`;
796 });
797 } else {
798 return replacement(...match, match.index, str, match.groups);
799 }
800 }
801 function matchAll(re, str) {
802 let match;
803 const matches = [];

Callers

nothing calls this directly

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected