+5
-1
@@ -6,3 +6,7 @@ "use strict"; | ||
| module.exports = function fmtr(str, obj) { | ||
| return _.template(_.isString(str) ? str : '', { interpolate: /\$\{([^\}]+)\}/gm })(obj); | ||
| try { | ||
| return _.template(_.isString(str) ? str : '', { interpolate: /\$\{([^\}]+)\}/gm })(obj); | ||
| } catch (err) { | ||
| return (_.isString(str) ? str : '').replace(/\$\{([^\}]+)\}/gm, ''); | ||
| } | ||
| }; |
+1
-1
| { | ||
| "name": "fmtr", | ||
| "version": "1.0.3", | ||
| "version": "1.0.4", | ||
| "description": "awesome string formatter", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -27,2 +27,7 @@ "use strict"; | ||
| it('should ignore undefined variables', function() { | ||
| expect(fmtr('Xx ${foobar} xX')).to.be('Xx xX'); | ||
| expect(fmtr('Xx ${foobar} xX', { baz: 123 })).to.be('Xx xX'); | ||
| }); | ||
| }); |
4466
7.48%33
32%