hops-config
Advanced tools
Comparing version 10.0.0-rc.4 to 10.0.0
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="10.0.0"></a> | ||
# [10.0.0](https://github.com/xing/hops/compare/v10.0.0-rc.4...v10.0.0) (2018-02-07) | ||
### Features | ||
* **config:** apply placeholders to plain objects, too ([b84b60c](https://github.com/xing/hops/commit/b84b60c)) | ||
<a name="9.5.0"></a> | ||
@@ -8,0 +19,0 @@ # [9.5.0](https://github.com/xing/hops/compare/v9.4.3...v9.5.0) (2018-01-09) |
26
index.js
@@ -6,7 +6,8 @@ 'use strict'; | ||
var cosmiconfig = require('cosmiconfig'); | ||
var mergeWith = require('lodash.mergewith'); | ||
var isPlainObject = require('is-plain-object'); | ||
var root = require('pkg-dir').sync(); | ||
var cosmiconfig = require('cosmiconfig'); | ||
function assign() { | ||
@@ -85,4 +86,3 @@ var args = Array.prototype.slice | ||
function resolvePlaceholders(config) { | ||
var keys = Object.keys(config); | ||
var regExp = new RegExp('<(' + keys.join('|') + ')>', 'g'); | ||
var regExp = new RegExp('<(' + Object.keys(config).join('|') + ')>', 'g'); | ||
function replaceRecursive(item) { | ||
@@ -92,5 +92,14 @@ if (Array.isArray(item)) { | ||
} | ||
if (isPlainObject(item)) { | ||
return Object.keys(item).reduce(function(result, key) { | ||
result[key] = replaceRecursive(item[key]); | ||
return result; | ||
}, {}); | ||
} | ||
if (typeof item === 'string') { | ||
return item.replace(regExp, function(_, match) { | ||
var result = config[match].toString(); | ||
return item.replace(regExp, function(_, configKey) { | ||
var result = config[configKey]; | ||
if (typeof result !== 'string') { | ||
result = String(result).toString(); | ||
} | ||
return regExp.test(result) ? replaceRecursive(result) : result; | ||
@@ -101,6 +110,3 @@ }); | ||
} | ||
return keys.reduce(function(result, key) { | ||
result[key] = replaceRecursive(config[key]); | ||
return result; | ||
}, {}); | ||
return replaceRecursive(config); | ||
} | ||
@@ -107,0 +113,0 @@ |
{ | ||
"name": "hops-config", | ||
"version": "10.0.0-rc.4", | ||
"version": "10.0.0", | ||
"description": "Hops core configuration", | ||
@@ -21,2 +21,3 @@ "keywords": [ | ||
"cosmiconfig": "^3.1.0", | ||
"is-plain-object": "^2.0.4", | ||
"lodash.mergewith": "^4.6.1", | ||
@@ -23,0 +24,0 @@ "pkg-dir": "^2.0.0" |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
19973
144
1
4
+ Addedis-plain-object@^2.0.4
+ Addedis-plain-object@2.0.4(transitive)
+ Addedisobject@3.0.1(transitive)