Skip to content

Commit

Permalink
Handle dashes
Browse files Browse the repository at this point in the history
  • Loading branch information
curran committed Nov 11, 2016
1 parent 07321aa commit b275e87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

});


Expand Down

0 comments on commit b275e87

Please sign in to comment.