frontend/.pnpm-store/v3/files/3b/b9816731552c3449b699e2f3261f08ba1bc11ab14fd9aad2454a5809132492718612f008187f24de6574884eaa7aab70729e6c35336d5b3200a52154e9aa69

17 lines
580 B
Plaintext

const ENV_EXPR = /(?<!\\)(\\*)\$\{([^${}]+)\}/g
export function envReplace(settingValue: string, env: NodeJS.ProcessEnv): string {
return settingValue.replace(ENV_EXPR, replaceEnvMatch.bind(null, env))
}
function replaceEnvMatch (env: NodeJS.ProcessEnv, orig: string, escape: string, name: string): string {
if (escape.length % 2) {
return orig.slice((escape.length + 1) / 2)
}
const envValue = env[name]
if (envValue === undefined) {
throw new Error(`Failed to replace env in config: ${orig}`)
}
return `${(escape.slice(escape.length / 2))}${envValue}`
}