interpolate-json
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -13,3 +13,4 @@ const extend = require('extend'); | ||
prefix: '${', | ||
suffix: '}' | ||
suffix: '}', | ||
subKeyPointer: '.' | ||
}; | ||
@@ -20,3 +21,5 @@ | ||
escapeRegex(opt.prefix.trim()) + | ||
'([\\s]*[\\w\\.]+[\\s]*)' + | ||
'([\\s]*[\\w]+(?:' + | ||
escapeRegex(opt.subKeyPointer.trim()) + | ||
'[\\w]+)*[\\s]*)' + | ||
escapeRegex(opt.suffix.trim()), | ||
@@ -43,5 +46,5 @@ 'g' | ||
const traverse = (obj, path) => { | ||
const traverse = (obj, path, subKeyPointer) => { | ||
let result = path | ||
.split('.') | ||
.split(subKeyPointer) | ||
.reduce((parent, key) => parent[key] || {}, obj); | ||
@@ -71,7 +74,7 @@ return type(result) === 'number' || type(result) === 'string' ? result : ''; | ||
const flattenAndResolve = (obj, matchSet, paramRegex) => { | ||
const flattenAndResolve = (obj, matchSet, paramRegex, subKeyPointer) => { | ||
let cache = {}; | ||
matchSet.forEach(match => { | ||
// Step 1: Get current value | ||
let curVal = traverse(obj, match); | ||
let curVal = traverse(obj, match, subKeyPointer); | ||
// Step 2: Is it clean | ||
@@ -90,3 +93,4 @@ if (paramRegex.test(curVal)) { | ||
getMatchSet(curVal.match(paramRegex), paramRegex), | ||
paramRegex | ||
paramRegex, | ||
subKeyPointer | ||
) | ||
@@ -118,3 +122,4 @@ ); | ||
getMatchSet(matches, paramRegex), | ||
paramRegex | ||
paramRegex, | ||
options.subKeyPointer | ||
); | ||
@@ -121,0 +126,0 @@ needToDo = true; |
{ | ||
"name": "interpolate-json", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Interpolate a Javascript (Node.js V8) Object or string with json - Advanced", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
8028
176