diff --git a/index.js b/index.js index e8a1625..362c2a3 100644 --- a/index.js +++ b/index.js @@ -45,7 +45,7 @@ var parseString = (function (){ // This regular expression detects instances of the // template parameter syntax such as {{foo}} or {{foo:someDefault}}. - var regex = /{{(\w|:|\s)+}}/g; + var regex = /{{(\w|:|\s|-)+}}/g; return function (str){ if(regex.test(str)){ diff --git a/test.js b/test.js index 45ae7f3..a26f6ce 100644 --- a/test.js +++ b/test.js @@ -76,6 +76,13 @@ describe("json-template", function() { assert.equal(template({ firstName: "Jane", lastName: "Doe" }), "Hello Jane Doe, how are you ?"); }); + it("should handle dashes in defaults", function() { + var template = parse("{{startTime:now-24h}}"); + assert.deepEqual(template.parameters, [{ key: "startTime", defaultValue: "now-24h" }]); + assert.equal(template({ startTime: "now-48h"}), "now-48h"); + assert.equal(template(), "now-24h"); + }); + });