Comparing version 0.1.1 to 1.0.0
@@ -14,7 +14,7 @@ var ConfJS, fs, path, _, | ||
_.defaults(this._options, { | ||
configFileParse: JSON.parse, | ||
parse: JSON.parse, | ||
encoding: 'utf8' | ||
}); | ||
this._data = this._options["default"] || {}; | ||
this.extendWithFile(this._getOptionWithKey('userConfig')); | ||
this.extendWithFile(this._options.userConfig); | ||
this.extendWithFile(this._getLocalConfigPath()); | ||
@@ -37,3 +37,6 @@ } | ||
ConfJS.prototype.get = function(key) { | ||
return this._getKeyFromObject(this._data, key); | ||
if (key == null) { | ||
return; | ||
} | ||
return _.getPath(this._data, key); | ||
}; | ||
@@ -56,26 +59,8 @@ | ||
ConfJS.prototype.parse = function(input) { | ||
return this._options.configFileParse(input); | ||
return this._options.parse(input); | ||
}; | ||
ConfJS.prototype._getKeyFromObject = function(object, key) { | ||
if (key == null) { | ||
return; | ||
} | ||
return _.getPath(object, key); | ||
}; | ||
ConfJS.prototype._getOptionKey = function(key) { | ||
return this._getKeyFromObject(this._options.keys, key); | ||
}; | ||
ConfJS.prototype._getOptionWithKey = function(key) { | ||
var get, getOptionKey; | ||
get = _.bind(this.get, this); | ||
getOptionKey = _.bind(this._getOptionKey, this); | ||
return _.compose(get, getOptionKey)(key); | ||
}; | ||
ConfJS.prototype._getLocalConfigPath = function() { | ||
var localConfigFile; | ||
localConfigFile = this._getOptionWithKey('localConfig'); | ||
localConfigFile = this._options.localConfig; | ||
if (localConfigFile == null) { | ||
@@ -82,0 +67,0 @@ return; |
{ | ||
"name": "conf.js", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "Support per-user and per-project configuration files out of the box", | ||
@@ -5,0 +5,0 @@ "main": "build/conf.js", |
conf.js | ||
======== | ||
[![npm version](https://badge.fury.io/js/conf.js.svg)](http://badge.fury.io/js/conf.js) | ||
[![dependencies](https://david-dm.org/resin-io/conf.js.png)](https://david-dm.org/resin-io/conf.js.png) | ||
[![Build Status](https://travis-ci.org/resin-io/conf.js.svg?branch=master)](https://travis-ci.org/resin-io/conf.js) | ||
conf.js allows you to get per-user and per-project configuration files out of the box. | ||
@@ -14,9 +18,5 @@ | ||
module.exports = new ConfJS | ||
keys: | ||
userConfig: 'configurationFiles.user' | ||
localConfig: 'configurationFiles.project' | ||
userConfig: path.join(process.env.HOME, '.myprojectrc.json') | ||
localConfig: '.myprojectrc.json' | ||
default: | ||
configurationFiles: | ||
user: path.join(process.env.HOME, '.myprojectrc.json') | ||
project: '.myprojectrc.json' | ||
@@ -48,7 +48,7 @@ # Your usual application settings | ||
Specify `keys.userConfig` to the defaults key that contains the user configuration file path. | ||
Specify `userConfig` to the user configuration file path. | ||
- Per-project configuration files: | ||
Specify `keys.localConfig` to the defaults key that contains the local configuration file path. | ||
Specify `localConfig` to the local configuration file name. | ||
@@ -73,6 +73,7 @@ Installation | ||
- `configFileParse`: The function used to parse inputs (defaults to `JSON.parse`). | ||
- `parse`: The function used to parse inputs (defaults to `JSON.parse`). | ||
- `encoding`: The encoding to be used when reading files (defaults to `utf8`). | ||
- `default`: Default settings. | ||
- `keys`: Provide semantic meaning to settings values, so `conf.js` can interpret them accordingly. | ||
- `userConfig`: The user config file path. | ||
- `localConfig`: The user local file name. | ||
@@ -117,3 +118,3 @@ ### settings.extendWithFile(file) | ||
Parse input given a function passed to `options.configFileParse`. | ||
Parse input given a function passed to `options.parse`. | ||
@@ -120,0 +121,0 @@ Tests |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
11
0
152
19634
190