Find, load and merge JSON and YAML config settings from one or more files, in the specified order.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.
Install with npm:
$ npm install --save merge-configs
This library makes it easy for your application to support config files similar to .eslintrc.json
, .travis.yml
, etc. by providing granular control over:
- the patterns and directories to search for config files
- how config files are loaded (or whether or not they should be loaded at all)
- which config files are merged, and how they are merged
const configs = require('merge-configs');
console.log(configs(name[, locations, options]));
Type: boolean
Default: undefined
Disable built-in loaders.
const mergeConfig = new MergeConfig({
options: {
builtins: false
}
});
Type: function
Default: undefined
Filter files that are resolved by glob patterns. Useful for conditionally filtering out files based on contents or other variables.
// can be defined on the ctor options
const mergeConfig = new MergeConfig({
options: {
filter: file => {
// "file" is an object with path properties
return file.basename === 'foo.json'
}
}
});
// or on the options for a specific config type
mergeConfig.type('local', {
cwd: process.cwd(),
patterns: ['*.json'],
filter: file => {
return file.basename !== 'foo.json';
}
});
name
{String} - (required) The module name (example:eslint
,babel
,travis
etc)types
{Array} - (optional) The config locations or "types" to search. If specified, only the given locations will be searched. If undefined, all locations are searched.options
{Object} - see all available options
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Jon Schlinkert
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on November 19, 2018.