string.format
Advanced tools
Comparing version 1.1.0 to 1.2.0
16
index.js
@@ -11,5 +11,19 @@ /* jslint node: true */ | ||
function format(string,params){ | ||
var replaced = string.replace(/\{([a-z0-9\$\_]+(?:\.[a-z0-9\-\_]+)*)\}/gmi,function(match,capture,index,all){ | ||
var replaced = string; | ||
replaced = replaced.replace(/\·\{(.*)\}\·/gmi,function(match,capture,index,all){ | ||
var replace; | ||
try { | ||
replace = eval(capture); | ||
replace = JSON.decycled(replace); | ||
if(typeof replace === 'string'){ | ||
replace = replace.replace(/(^\"|\"$)/g,'').replace(/(\\n|\\r)/g,'\n').replace(/\\t/g,'\t'); | ||
} | ||
return replace; | ||
} catch(error){ | ||
return match; | ||
} | ||
}); | ||
replaced = replaced.replace(/\{([a-z0-9\$\_]+(?:\.[a-z0-9\-\_]+)*)\}/gmi,function(match,capture,index,all){ | ||
var replace; | ||
try { | ||
capture = '["'+capture.split('.').join('"]["')+'"]'; | ||
@@ -16,0 +30,0 @@ replace = eval('params'+capture); |
{ | ||
"name": "string.format", | ||
"description": "String prototype method -> 'Hello {name}!'.format({name:'Homer'});", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Bifuer", |
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
6361
37
2