mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
12 lines
376 B
JavaScript
12 lines
376 B
JavaScript
/**
|
|
* expandEnvs Replaces $var in args and command with environment variables
|
|
* if the environment variable doesn't exist, it leaves it as is.
|
|
*/
|
|
export function expandEnvs(str, envs) {
|
|
return str.replace(/(?<!\\)\$[a-zA-Z0-9_]+/g, (varName) => {
|
|
const varValue = envs[varName.slice(1)];
|
|
// const test = 42;
|
|
return varValue ?? varName;
|
|
});
|
|
}
|