Comparing version 4.0.0 to 4.0.2
@@ -37,3 +37,3 @@ var getVar = require('./get_var.js') | ||
// empty or unchanged value signal otherwise | ||
if (notEmpty(value) && value !== config[key]) | ||
if (notEmpty(value)) | ||
{ | ||
@@ -40,0 +40,0 @@ config[key] = value; |
@@ -5,5 +5,7 @@ var path = require('path') | ||
, typeOf = require('precise-typeof') | ||
, stripBOM = require('strip-bom') | ||
, stripBOM = require('stripbom') | ||
, applyHooks = require('./apply_hooks.js') | ||
, getCacheKey = require('./get_cache_key.js') | ||
, getFiles = require('./get_files.js') | ||
, mergeLayers = require('./merge_layers.js') | ||
, resolveExts = require('./resolve_exts.js') | ||
@@ -120,3 +122,3 @@ ; | ||
/** | ||
* Loads and parses provided file (synchronious). | ||
* Loads and parses provided file (synchronous). | ||
* | ||
@@ -134,3 +136,3 @@ * @param {string} file - absolute path to the file | ||
content = stripBOM(fs.readFileSync(file, {encoding: 'utf8'})); | ||
// provide filepath as the second argument for complex parsing, | ||
// provide file path as the second argument for complex parsing, | ||
// also it matches `module._compile` nodejs API. | ||
@@ -149,54 +151,1 @@ // Note: JSON.parse accepts two arguments, but ignores anything | ||
} | ||
/** | ||
* Applies matched hooks | ||
* | ||
* @param {object} config - config object to apply hooks to | ||
* @param {string} filename - base filename to match hooks against | ||
* @returns {object} - modified config object | ||
*/ | ||
function applyHooks(config, filename) | ||
{ | ||
Object.keys(this.hooks).forEach(function(hook) | ||
{ | ||
// in order to match hook should either the same length | ||
// as the filename or smaller | ||
if (filename.substr(0, hook.length) === hook) | ||
{ | ||
config = this.hooks[hook](config); | ||
} | ||
}.bind(this)); | ||
return config; | ||
} | ||
/** | ||
* Merges provided layers into a single config object, | ||
* respecting order of the layers | ||
* | ||
* @param {array} layers - list of config objects | ||
* @returns {object} - single config object | ||
*/ | ||
function mergeLayers(layers) | ||
{ | ||
var _instance = this | ||
, result = {} | ||
; | ||
layers.forEach(function(layer) | ||
{ | ||
layer.exts.forEach(function(ext) | ||
{ | ||
ext.dirs.forEach(function(cfg) | ||
{ | ||
// have customizable's array merge function | ||
result = merge.call({ | ||
useCustomAdapters: merge.behaviors.useCustomAdapters, | ||
'array': _instance.arrayMerge | ||
}, result, cfg.config); | ||
}); | ||
}); | ||
}); | ||
return result; | ||
} |
@@ -15,3 +15,3 @@ var getVar = require('./get_var.js') | ||
* @param {object} env - object to search within | ||
* @returns {string|boolean} - replaced string or `false` | ||
* @returns {string|boolean} - replaced string or empty string | ||
* if no matching variables found | ||
@@ -36,8 +36,8 @@ */ | ||
}); | ||
// reset entry if no variables were resolved | ||
if (!found) entry = ''; | ||
} | ||
// reset entry if no variables were resolved | ||
if (!found) entry = ''; | ||
return entry; | ||
} |
{ | ||
"name": "configly", | ||
"version": "4.0.0", | ||
"version": "4.0.2", | ||
"description": "A developer-friendly lightweight replacement for the 'config' module that works with custom config directory and pluggable parsers", | ||
@@ -44,3 +44,6 @@ "main": "index.js", | ||
"toml", | ||
"yaml" | ||
"yaml", | ||
"sdk", | ||
"toolkit", | ||
"diy" | ||
], | ||
@@ -56,21 +59,21 @@ "author": "Alex Indigo <iam@alexindigo.com>", | ||
"precise-typeof": "^1.0.2", | ||
"strip-bom": "^2.0.0" | ||
"stripbom": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "^1.10.0", | ||
"coveralls": "^2.11.9", | ||
"coveralls": "^2.11.12", | ||
"cson": "^3.0.2", | ||
"eslint": "^2.9.0", | ||
"eslint": "^2.13.1", | ||
"hjson": "^1.8.4", | ||
"ini": "^1.3.4", | ||
"js-yaml": "^3.6.0", | ||
"js-yaml": "^3.6.1", | ||
"json5": "^0.5.0", | ||
"nyc": "^6.4.2", | ||
"pre-commit": "^1.1.2", | ||
"nyc": "^7.1.0", | ||
"pre-commit": "^1.1.3", | ||
"properties": "^1.2.1", | ||
"sinon": "^1.17.4", | ||
"sinon": "^1.17.5", | ||
"tap-spec": "^4.1.1", | ||
"tape": "^4.5.1", | ||
"tape": "^4.6.0", | ||
"toml": "^2.3.0" | ||
} | ||
} |
@@ -149,3 +149,2 @@ # configly [![NPM Module](https://img.shields.io/npm/v/configly.svg?style=flat)](https://www.npmjs.com/package/configly) | ||
var path = require('path'); | ||
var ini = require('ini'); | ||
var configly = require('configly'); | ||
@@ -236,3 +235,3 @@ | ||
### Migration From `config` | ||
### Migration from `config` | ||
@@ -307,2 +306,57 @@ To fully replicate `config`'s behavior and provide easy way to include static customized config | ||
`app/lib/file.js` | ||
```javascript | ||
var config = require('config'); | ||
console.log('value', config.my.data.from.etc.consul.myApp.json); | ||
``` | ||
### Base for Custom Module | ||
And similar to the method described above, it could serve as a handy toolkit for your own config module, | ||
below you can see simple example of the custom config module that allows for flexible extension on per project basis | ||
while keeping standard approach within your organization. | ||
```javascript | ||
var path = require('path') | ||
, configly = require('configly') | ||
// get application's name for per application custom config file, | ||
// useful for having per environment specific config files | ||
// separate from code base of the application | ||
, appName = process.env['NODE_MY_ORG_CONFIG_APPNAME'] || require(path.resolve('./package.json')).name | ||
// by default, it will search local (CWD) `./config` directory | ||
// augmented with same files from environment specific folder `/etc/consul`, | ||
// and could overridden from outside of the app, for cases when app/module itself | ||
// being used as the base for another service, or in test/integration environments | ||
, directory = process.env['NODE_MY_ORG_CONFIG_PATH'] || './config:/etc/consul' | ||
// use standard path separator `:` | ||
, separator = ':' | ||
; | ||
// run configly once with inlined modifiers | ||
// and have it as node-cached module | ||
module.exports = configly({ | ||
defaults: { | ||
directory: directory.split(separator) | ||
}, | ||
// also will try to load config files matching current app name | ||
// e.g. 'my-app.js', `my-app.json`, | ||
// `my-app-production.js`, `my-app-production.json`, | ||
// from both local `config` folder and from `/etc/consul`. | ||
// Also `appName` could be composite value, like: | ||
// `my_app:my_group:my_org` for more flexibility | ||
files: configly.files.concat(appName.split(separator)) | ||
}); | ||
``` | ||
Above code could be published on npm (internal or public), as your organization specific config module `@myorg/config`, | ||
and used within all your organization's projects: | ||
```javascript | ||
var config = require('@myorg/config'); | ||
console.log(config.env.specific.value); | ||
``` | ||
### More Examples | ||
@@ -309,0 +363,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
33756
18
641
387
0
+ Addedstripbom@^3.0.0
+ Addedstripbom@3.0.0(transitive)
- Removedstrip-bom@^2.0.0
- Removedis-utf8@0.2.1(transitive)
- Removedstrip-bom@2.0.0(transitive)