json-templater
Advanced tools
Comparing version 1.0.4 to 1.1.0
{ | ||
"name": "json-templater", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Simple json/js object template strings", | ||
@@ -5,0 +5,0 @@ "main": "template.js", |
@@ -39,2 +39,8 @@ suite('string', function() { | ||
verify( | ||
'nested token false value', | ||
['{{foo.bar}}', { foo: { bar: false} }], | ||
'false' | ||
); | ||
verify( | ||
'replace in the middle of string', | ||
@@ -41,0 +47,0 @@ [ |
@@ -56,17 +56,18 @@ /** | ||
var result; | ||
var replaced = input.replace(REGEX, function(whole, path) { | ||
var replaced = input.replace(REGEX, function(original, path) { | ||
var value = extractValue(path, view); | ||
if (value) { | ||
if (typeof value === 'object') { | ||
result = value; | ||
return; | ||
} else { | ||
return value; | ||
} | ||
if (undefined === value || null === value) { | ||
return original; | ||
} | ||
return whole; | ||
if (typeof value === 'object') { | ||
result = value; | ||
return; | ||
} | ||
return value; | ||
}); | ||
return result ? result : replaced; | ||
return (undefined !== result) ? result : replaced; | ||
} | ||
module.exports = replace; |
10642
333