1.15.2 • Published 2 years ago
@tuplo/envsubst v1.15.2
envsubst
Substitutes the values of environment variables. Based on GNU envsubst.
Usage
import envsubst from '@tuplo/envsubst';
Substitutes the values of environment variables
process.env = { ENV_VAR1: 'bar' };
envsubst('foo=$ENV_VAR1'); // → foo=bar
envsubst('foo=${ENV_VAR1}'); // → foo=bar
envsubst('foo={{ENV_VAR1}}'); // → foo=bar
If shellFormat
is present, replaces only those variables
process.env = { ENV_VAR1: 'bar', ENV_VAR2: 'baz' };
envsubst('$ENV_VAR1 $ENV_VAR2', '$ENV_VAR2'); // → $ENV_VAR1 baz
API
envsubst(input, shellFormat)
input: string
A string with references to environment variables of the form $VARIABLE
, ${VARIABLE}
or {{VARIABLE}}
.
shellFormat: string
The output consists of the environment variables that are referenced in shellFormat
.
Install
$ npm install @tuplo/envsubst
# or with yarn
$ yarn add @tuplo/envsubst
Contribute
Contributions are always welcome!
License
MIT