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

Method replace

benchmark/data-min.js:649–672  ·  view source on GitHub ↗
(t, e)

Source from the content-addressed store, hash-verified

647 return this.original !== this.toString();
648 }
649 replace(t, e) {
650 function n(r, s) {
651 return typeof e == 'string'
652 ? e.replace(/\$(\$|&|\d+)/g, (h, o) =>
653 o === '$' ? '$' : o === '&' ? r[0] : +o < r.length ? r[+o] : `$${o}`,
654 )
655 : e(...r, r.index, s, r.groups);
656 }
657 function i(r, s) {
658 let h;
659 const o = [];
660 for (; (h = r.exec(s)); ) o.push(h);
661 return o;
662 }
663 if (typeof t != 'string' && t.global)
664 i(t, this.original).forEach((s) => {
665 s.index != null && this.overwrite(s.index, s.index + s[0].length, n(s, this.original));
666 });
667 else {
668 const r = this.original.match(t);
669 r && r.index != null && this.overwrite(r.index, r.index + r[0].length, n(r, this.original));
670 }
671 return this;
672 }
673}
674const v = Object.prototype.hasOwnProperty;
675class S {

Callers 11

benchFunction · 0.45
trimEndMethod · 0.45
trimStartMethod · 0.45
indentMethod · 0.45
trimEndAbortedMethod · 0.45
trimStartAbortedMethod · 0.45
nMethod · 0.45
indentMethod · 0.45
trimStartMethod · 0.45
trimEndMethod · 0.45

Calls 1

overwriteMethod · 0.95

Tested by

no test coverage detected