config-template-merger
v1.0.44
Published
Utility for merging config json from various files
Downloads
6
Readme
config-template-merger
Utility for merging json configs through various JSONs together, and by replacing variables.
Setup
Directly in web page
Include the scripts in html as follow:
<script src="https://unpkg.com/config-template-merger/public/config-merger.js"></script>
Through NPM
Add to package.json
:
"dependencies": {
...
"config-template-merger": "^1.0.0",
...
}
Use Browserify to make classes available in browser
In package.json
:
"scripts": {
...
"browserify": "browserify browserify/main.js -s dok-lib -o public/gen/compact.js",
...
},
In browserify/main.js
:
const { ConfigMerger } = require('config-template-merger');
module.exports = {
ConfigMerger,
};
Components
ConfigMerger
Description
ConfigMerger is used to compose templates using various
Usage
path/test-template.json
{ "field2" : 345 }
const configMerger = new ConfigMerger(fileUtils, {
constant: 567,
});
const source = {
"field1": 123,
template: "test-template.json",
"field3": "{constant * 10}",
"multiField": {
"repeat": 5,
"value": "{index * 2}"
},
};
const result = await configMerger.process(source, "path/", {
viewportSize: [100, 200],
});
/* RESULT
{
field2: 345,
field1: 123,
field3: 5670,
multiField: [
{ value: 0 },
{ value: 2 },
{ value: 4 },
{ value: 6 },
{ value: 8 }
]
}
*/