Comparing version 0.5.5 to 0.6.0
27
index.js
@@ -11,3 +11,3 @@ #! /usr/bin/env node | ||
module.exports = function (name, defaults, argv) { | ||
module.exports = function (name, defaults, argv, parse) { | ||
if('string' !== typeof name) | ||
@@ -22,2 +22,9 @@ throw new Error('rc(name): name *must* be string') | ||
parse = parse || cc.parse | ||
function file () { | ||
var content = cc.file.apply(null, arguments) | ||
return content ? parse(content) : null | ||
} | ||
var local = cc.find('.'+name+'rc') | ||
@@ -29,12 +36,12 @@ | ||
defaults, | ||
win ? {} : cc.json(join(etc, name, 'config')), | ||
win ? {} : cc.json(join(etc, name + 'rc')), | ||
home ? cc.json(join(home, '.config', name, 'config')) : {}, | ||
home ? cc.json(join(home, '.config', name)) : {}, | ||
home ? cc.json(join(home, '.' + name, 'config')) : {}, | ||
home ? cc.json(join(home, '.' + name + 'rc')) : {}, | ||
cc.json(local), | ||
win ? {} : file(join(etc, name, 'config')), | ||
win ? {} : file(join(etc, name + 'rc')), | ||
home ? file(join(home, '.config', name, 'config')) : {}, | ||
home ? file(join(home, '.config', name)) : {}, | ||
home ? file(join(home, '.' + name, 'config')) : {}, | ||
home ? file(join(home, '.' + name + 'rc')) : {}, | ||
file(local), | ||
local ? {config: local} : null, | ||
env.config ? cc.json(env.config) : null, | ||
argv.config ? cc.json(argv.config) : null, | ||
env.config ? file(env.config) : null, | ||
argv.config ? file(argv.config) : null, | ||
env, | ||
@@ -41,0 +48,0 @@ argv |
@@ -19,3 +19,3 @@ var fs = require('fs') | ||
var json = exports.json = function () { | ||
var file = exports.file = function () { | ||
var args = [].slice.call(arguments).filter(function (arg) { return arg != null }) | ||
@@ -31,9 +31,13 @@ | ||
try { | ||
content = fs.readFileSync(file,'utf-8') | ||
return fs.readFileSync(file,'utf-8') | ||
} catch (err) { | ||
return | ||
} | ||
return parse(content) | ||
} | ||
var json = exports.json = function () { | ||
var content = file.apply(null, arguments) | ||
return content ? parse(content) : null | ||
} | ||
var env = exports.env = function (prefix, env) { | ||
@@ -40,0 +44,0 @@ env = env || process.env |
{ | ||
"name": "rc", | ||
"version": "0.5.5", | ||
"version": "0.6.0", | ||
"description": "hardwired configuration loader", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -120,3 +120,15 @@ # rc | ||
## Pass in your own parser | ||
If you have a special need to use a non-standard parser, | ||
you can do so by passing in the parser as the 4th argument. | ||
(leave the 3rd as null to get the default args parser) | ||
```javascript | ||
require('rc')(appname, defaults, null, parser); | ||
``` | ||
This may also be used to force a more strict format, | ||
such as strict, valid JSON only. | ||
## Note on Performance | ||
@@ -123,0 +135,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14052
210
141