Expands expressions in config files
import { expand } from "config-expander";
// expanding hole expressions at the value position (result key is a number)
expand({ key: "${value + 1}" }, { constants: { value: 77 } }).then(r =>
console.log(JSON.stringify(r))
);
// calculate port numbers
expand({ constants: { base: 10000 }, http: { port: "${base + 1}" } }).then(r =>
console.log(JSON.stringify(r))
);
// load config from file
expand("${include('tests/fixtures/other.json')}").then(r =>
console.log(JSON.stringify(r))
);
{ "key" : 78 }
{ "constants": { "base": 10000 }, "http": { "port": 10001 }}
{ "key": "value from other" }
const configuration await expand("${include('" + '/path/to/the/config.json' + "')}")
{
"ca": "${document(os.home + '/ca.pem')}"
}
{
"http-port": "${base + 0}",
"https-port": "${base + 1}"
}
{
"copy-cmd": "${os.platform == 'win32' ? 'copy' : 'cp'}"
}
Predefined constants
Type: Object
env
Object environment variables from process.envos
Object os modulebasedir
string filesystem configuration start point
Expands expressions in a configuration object
Returns Promise<Object> resolves to the expanded configuration
Type: Object
Type: Object
Type: Function
Type: Object
knwon functions
Include definition form a file.
file
string file name to be included
Returns string content of the file
Replace string.
source
string input value
Returns string replaced content
Convert string into upper case.
source
string input value
Returns string uppercase result
Convert string into lower case.
source
string input value
Returns string lowercase result
Split source string on pattern boundaries.
Returns Array<string> separated source
Encrypt a plaintext value.
Returns string encrypted value
Decrypt a former encrypted string.
Returns string plaintext
Call executable.
Returns string stdout
merge from b into a When a and b are arrays of values only the none duplaces are appendend to a
a
anyb
any
Returns any merged b into a
With npm do:
npm install config-expander
BSD-2-Clause