(s: string, env: NodeJS.ProcessEnv = process.env)
| 18 | * to prevent the bug from silently regressing during refactors. |
| 19 | */ |
| 20 | export function expandEnvString(s: string, env: NodeJS.ProcessEnv = process.env): string { |
| 21 | if (typeof s !== 'string') return s; |
| 22 | return s |
| 23 | .replace(/\$\$/g, '\u0000DOLLAR\u0000') // escape $$ temporarily |
| 24 | .replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_, name) => env[name] ?? '') |
| 25 | .replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g, (_, name) => env[name] ?? '') |
| 26 | .replace(/\u0000DOLLAR\u0000/g, '$'); |
| 27 | } |
| 28 | |
| 29 | /** Apply expandEnvString to every value in a string-keyed map. */ |
| 30 | export function expandEnvObject( |
no outgoing calls
no test coverage detected