Merge a config with a config template
This module allows developers of applications to define a template of a configuration object. At runtime, this template can then be merged with the user defined config object adding new or removing old properties.
$ npm install --save human-config-merge
const merge = require('human-config-merge');
// The config template
const template = `
{
// Some unicorn
"unicorn": "🌈",
"git": {
// Your GitHub username
"username": "",
// A GitHub API key
"apiKey": ""
}
}
`;
// The current config
const config = `
{
// Some unicorn
"unicorn": "🦄",
"git": {
// Your GitHub username
"username": "SamVerschueren",
// The old GitHub API key
"key": "1234"
}
}
`;
merge(template, config);
/*
{
// Some unicorn
"unicorn": "🦄",
"git": {
// Your GitHub username
"username": "SamVerschueren",
// A GitHub API key
"apiKey": ""
}
}
*/
Type: string
Template config string.
Type: string
Current config string.
MIT © Sam Verschueren