Expands expressions in config files
npm install config-expander










Expands expressions in config files
``js
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))
);
`
`json`
{ "key" : 78 }
{ "constants": { "base": 10000 }, "http": { "port": 10001 }}
{ "key": "value from other" }
`js`
const configuration await expand("${include('" + '/path/to/the/config.json' + "')}")
`json`
{
"ca": "${document(os.home + '/ca.pem')}"
}
`json`
{
"http-port": "${base + 0}",
"https-port": "${base + 1}"
}
`json`
{
"copy-cmd": "${os.platform == 'win32' ? 'copy' : 'cp'}"
}
* defaultConstants
* Properties
* expand
* Parameters
* Context
* Properties
* Value
* Properties
* Apply
* Parameters
* ConfigFunction
* Properties
* functions
* include
* Parameters
* replace
* Parameters
* toUpperCase
* Parameters
* toLowerCase
* Parameters
* split
* Parameters
* encrypt
* Parameters
* decrypt
* Parameters
* spawn
* Parameters
* merge
* Parameters
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
* config Object config sourceoptions
* Object the options
* options.constants Object additional constantsoptions.default
* Object default configurationoptions.functions
* Object additional functions
Returns Promise<Object> resolves to the expanded configuration
Type: Object
* constants Object
* constants.basedir string constants.env
* Object constants.os
* string functions
* Object
Type: Object
Type: Function
* context Context args
* Array<Value>
Type: Object
* arguments Array<string> returns
* string apply
* Apply
knwon functions
Include definition form a file.
#### Parameters
* file string file name to be included
Returns string content of the file
Replace string.
#### Parameters
* source string input value
Returns string replaced content
Convert string into upper case.
#### Parameters
* source string input value
Returns string uppercase result
Convert string into lower case.
#### Parameters
* source string input value
Returns string lowercase result
Split source string on pattern boundaries.
#### Parameters
* source string pattern
* string
Returns Array<string> separated source
Encrypt a plaintext value.
#### Parameters
* key string plaintext
* string input value
Returns string encrypted value
Decrypt a former encrypted string.
#### Parameters
* key string encrypted
* string
Returns string plaintext
Call executable.
#### Parameters
* executable string patharguments
* Array<string> options
* Object?
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 any b
* any
Returns any merged b into a
With npm do:
`shell``
npm install config-expander
BSD-2-Clause