(searchValue, replacement)
| 785 | return this.original !== this.toString(); |
| 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 = []; |
| 804 | while ((match = re.exec(str))) { |
| 805 | matches.push(match); |
| 806 | } |
| 807 | return matches; |
| 808 | } |
| 809 | if (typeof searchValue !== 'string' && searchValue.global) { |
| 810 | const matches = matchAll(searchValue, this.original); |
| 811 | matches.forEach((match) => { |
| 812 | if (match.index != null) |
| 813 | this.overwrite( |
| 814 | match.index, |
| 815 | match.index + match[0].length, |
| 816 | getReplacement(match, this.original), |
| 817 | ); |
| 818 | }); |
| 819 | } else { |
| 820 | const match = this.original.match(searchValue); |
| 821 | if (match && match.index != null) |
| 822 | this.overwrite( |
| 823 | match.index, |
| 824 | match.index + match[0].length, |
| 825 | getReplacement(match, this.original), |
| 826 | ); |
| 827 | } |
| 828 | return this; |
| 829 | } |
| 830 | } |
| 831 | const hasOwnProp = Object.prototype.hasOwnProperty; |
| 832 | class Bundle { |
no test coverage detected