A system for gathering configuration/preference files from along your current path, combining them together.
A system for gathering configuration/preference files from along your current path, combining them together. Will also handle user-scoped preference files in your home directory (in the correct spot for your OS.)
npm install sumconfig
(There will be more here once I write the CLI)
.${appName}rc
.${appName}rc.json
.${appName}rc.yml
.${appName}rc.yaml
.${appName}rc.js
.${appName}rc.mjs
${appName}.config.yml
${appName}.config.yaml
${appName}.config.js
${appName}.config.mjs
"type": "module"
, then you can use{
"appName": {
"foo": 12
}
}
import sumconfig from 'sumconfig'
const config = sumconfig('foo', opts)
Option | Type | Default | Meaning |
---|---|---|---|
errorOnEmpty | boolean | false | If there is a file that exists, but is empty, throw an error before trying to parse it. |
loaders | {[x: string]: Loader} | import {loaders} from 'sumconfig' |
How to load a file of the given name, or with the given extension. Use "" for files with no extension (default for this case is YAML, which also handles JSON). |
startDir | string | process.cwd() |
Where to start the search? |
stopDir | string | os.homedir() |
If we get to this directory before the root directory, stop. |
dirs | string[] | undefined | If defined, use this list of directories instead of walking up parent directories from startDir to stopDir. |
fileNames | string[] |
import {fileNames} from 'sumconfig' fileNames(appName)
|
Try each of these filenames at each level of the path. |