mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
This pull request adds support for expanding environment variable expansion support. Closes #91 Since the user controls the call site of cmd-env, it only supports basic UNIX style $var format. `%var%` (windows) or `${var}` is not supported. However, you can escape variable expansion by escaping the dollar sign like so `\$`. Signed-off-by: omeid matten <public@omeid.me>
14 lines
470 B
JavaScript
14 lines
470 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
/**
|
|
* expandEnvs Replaces $var in args and command with environment variables
|
|
* the environment variable doesn't exist, it leaves it as is.
|
|
*/
|
|
function expandEnvs(str, envs) {
|
|
return str.replace(/(?<!\\)\$[a-zA-Z0-9_]+/g, varName => {
|
|
const varValue = envs[varName.slice(1)];
|
|
return varValue === undefined ? varName : varValue;
|
|
});
|
|
}
|
|
exports.expandEnvs = expandEnvs;
|