( template: string, replacer: (match: string, index: number, template: string) => Promise<string> )
| 74 | } |
| 75 | |
| 76 | async function replaceValidReferencesAsync( |
| 77 | template: string, |
| 78 | replacer: (match: string, index: number, template: string) => Promise<string> |
| 79 | ): Promise<string> { |
| 80 | const pattern = createReferencePattern() |
| 81 | let cursor = 0 |
| 82 | let result = '' |
| 83 | for (const match of template.matchAll(pattern)) { |
| 84 | const fullMatch = match[0] |
| 85 | const index = match.index ?? 0 |
| 86 | result += template.slice(cursor, index) |
| 87 | result += isLikelyReferenceSegment(fullMatch) |
| 88 | ? await replacer(fullMatch, index, template) |
| 89 | : fullMatch |
| 90 | cursor = index + fullMatch.length |
| 91 | } |
| 92 | return result + template.slice(cursor) |
| 93 | } |
| 94 | |
| 95 | async function replaceEnvVarsAsync( |
| 96 | template: string, |
no test coverage detected