The string to expand.
The reference object to use for variable expansion.
The expanded string, or undefined when it is empty.
process.env.FOO = 'bar';
dotenvExpand('Hello $FOO'); // "Hello bar"
dotenvExpand('Hello $BAZ:world'); // "Hello world"
dotenvExpand('Price \\$5'); // "Price $5"
ref holds composed values: each has already been expanded once, so a
referenced value is substituted verbatim and never expanded again (#94).
With ref = { P: '$5' }, $P expands to $5. Only a default is expanded,
by the same rules. The text is scanned once, left to right, and each
substituted value is spliced in as-is (it is not re-scanned with the text
around it):
\$ is a literal $.$ that starts no reference (cost $, $!) stays literal, and the
other references in the value are still expanded.$HOST:8080 reads
8080 as HOST's default; write ${HOST}:8080. There is no :- form:
${A:-x} has the default -x.P,
P=${P:/usr/bin}:/x expands to /usr/bin:/x.
Expands environment-variable references in a string. References may be written
$VAR[:default]or${VAR[:default]}; unknown variables without a default expand to the empty string.