(input: string, replacer: (match: string, count: number) => string | null)
| 655 | } |
| 656 | |
| 657 | function replaceVariablesMatches(input: string, replacer: (match: string, count: number) => string | null) { |
| 658 | const matches = getVariablesMatches(input); |
| 659 | const matchesCount = matches.length; |
| 660 | if (matchesCount === 0) { |
| 661 | return input; |
| 662 | } |
| 663 | |
| 664 | const inputLength = input.length; |
| 665 | const replacements = matches.map((m) => replacer(m.value, matches.length)); |
| 666 | const parts: Array<string | null> = []; |
| 667 | parts.push(input.substring(0, matches[0].start)); |
| 668 | for (let i = 0; i < matchesCount; i++) { |
| 669 | parts.push(replacements[i]); |
| 670 | const start = matches[i].end; |
| 671 | const end = i < matchesCount - 1 ? matches[i + 1].start : inputLength; |
| 672 | parts.push(input.substring(start, end)); |
| 673 | } |
| 674 | return parts.join(''); |
| 675 | } |
| 676 | |
| 677 | function getVariableNameAndFallback(match: string) { |
| 678 | const commaIndex = match.indexOf(','); |
no test coverage detected