interpolate-json
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -99,2 +99,3 @@ const extend = require('extend'); | ||
do: (obj, values = null, options = {}) => { | ||
let needToDo = false; | ||
let objType = type(obj); | ||
@@ -108,11 +109,17 @@ if (options.prefix && !options.suffix) options.suffix = ''; | ||
obj = JSON.stringify(obj); | ||
let matches = obj.match(paramRegex); | ||
values = flattenAndResolve( | ||
cachedValue, | ||
getMatchSet(matches, paramRegex), | ||
paramRegex | ||
); | ||
if (paramRegex.test(obj)) { | ||
let matches = obj.match(paramRegex); | ||
values = flattenAndResolve( | ||
cachedValue, | ||
getMatchSet(matches, paramRegex), | ||
paramRegex | ||
); | ||
needToDo = true; | ||
} | ||
break; | ||
case 'string': | ||
log(`Input: "${obj}"`); | ||
if (paramRegex.test(obj)) needToDo = true; | ||
else break; | ||
if (null === values) { | ||
@@ -126,3 +133,3 @@ traceNThrow('Please provide "values"', BadRequest); | ||
} | ||
const result = getInterpolated(obj, paramRegex, values); | ||
const result = needToDo ? getInterpolated(obj, paramRegex, values) : obj; | ||
switch (objType) { | ||
@@ -129,0 +136,0 @@ case 'Object': |
{ | ||
"name": "interpolate-json", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Interpolate a Javascript (Node.js V8) Object or string with json - Advanced", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
7816
171