Open davidmoshal opened 4 years ago
You can use the internal parser which the envsub
CLI tool uses.
Quick example:
const parseEnv = require("envsub/js/envsub-parser");
const envParserConfig = {
outputFile: null,
options: {
all: false,
diff: false,
protect: false,
syntax: "dollar-both",
},
cli: false,
};
const data = {
name: "$PATH",
};
const content = parseEnv(JSON.stringify(data), envParserConfig);
console.log(content); // "{\"name\":\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"}"
Hope this helps
ie: given a string representing a
.env
file and a template string, return another string with substituted variables.ps: awesome library, thanks so much for creating it !