lconf
v0.0.5
Published
parse local configuration files of various types
Downloads
1
Readme
lconf
parse local configuration files of various types. currently supported filetypes: json
,yaml
,yml
,js
(must module.exports = {};
)
api
lconf supports three methods:
parse(file:string, [regex:RegExp]):
parses a configuration file located atfile
. note: iffile
is relative, it will be resolved fromprocess.cwd()
. iffile
is a directory, all files inside the directory will be included. ifregex
is given,file
(if actual file) or all files in directory (iffile
is a directory) will be compared against regex, and added ifregex.test(filePath)
returnstrue
.suppress(bool:boolean[default=true]):
toggles throwing of exceptions when parsing. usingsuppress()
will prevent throwing of errors.opts():
does the actual parse, and throws errors if there are any, and we aren'tsuppress()
-ed.
these methods can be chained together:
var lconf = require('lconf');
// parse multiple configuration files
var config = lconf().parse('./config.yaml').parse('./config.json').opts();
the resulting object will look like:
{
"./config.yaml": {...},
"./config.json": {...}
}
If you want to smash configuration variables into one object, see bengreenier/hulksmash.
examples
parse some config files that may or may not be present:
var lconf = require('lconf');
// parse multiple configuration files
var config = lconf()
.parse('./idk.yaml')
.parse('./if.json')
.parse('./these.json')
.parse('./are.json')
.parse('./present.js')
.suppress()
.opts();
// could check config object keys to see what succeeded
reuse parsing instance:
var lconf = require('lconf');
// parse multiple configuration files
var parser = lconf();
var config = parser
.parse('./config.yaml')
.parse('./config.json')
.opts();
var settings = parser
.parse('./settings.yaml')
.parse('./settings.json')
.opts();
// config will have two keys (one for each .parse() filename)
// settings will have two as well.
// each call to .opts() clears previously parsed data