diff --git a/lib/template.js b/lib/template.js index 2635e4b..2527d77 100644 --- a/lib/template.js +++ b/lib/template.js @@ -47,12 +47,12 @@ JsonTemplate.prototype.compile = function() { function parse(item) { let matched = false; - const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:]+))?(:(\w+))?)\}/g; + const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:]+))?(:(\w+))?)\}/g; /* eslint-disable no-cond-assign */ while (match = templates.exec(item)) { /* eslint-enable no-cond-assign */ matched = true; - const param = /([[\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:]+))?(:(\w+))?/.exec(match[1]); + const param = /([[\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:]+))?(:(\w+))?/.exec(match[1]); if (!param || !param[1]) { throw new Error(g.f('Invalid parameter: %s', match[1])); } @@ -120,7 +120,7 @@ JsonTemplate.prototype.build = function(parameters) { function transform(obj) { return traverse(obj).map(function(item) { const ctx = this; - const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:\{\}]+))?(:(\w+))?)\}/g; + const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:\{\}]+))?(:(\w+))?)\}/g; function build(item) { let match = null; const parsed = []; @@ -134,7 +134,7 @@ JsonTemplate.prototype.build = function(parameters) { parsed.push(item.substring(index, match.index)); } // The variable pattern is {name=defaultValue:type} - const param = /([\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:\{\}]+))?(:(\w+))?/.exec(match[1]); + const param = /([\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:\{\}]+))?(:(\w+))?/.exec(match[1]); if (!param || !param[1]) { throw new Error(g.f('Invalid parameter: %s', match[1])); }