Skip to content

Commit

Permalink
added whitespace support
Browse files Browse the repository at this point in the history
  • Loading branch information
pazhersh committed May 21, 2024
1 parent 38a5658 commit 4141096
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const renderRecursively = (inputJson, template, execOptions = {}) => {
const SPREAD_KEYWORD = "spreadValue";
const keywordMatcher = `^\\{\\{\\s*${SPREAD_KEYWORD}\\(\s*\\)\\s*\\}\\}$`; // matches {{ <Keyword>() }} with white spaces where you'd expect them

if (key.match(keywordMatcher)) {
if (key.trim().match(keywordMatcher)) {
const evaluatedValue = renderRecursively(inputJson, value, execOptions);
if (typeof evaluatedValue !== "object") {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion test/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('template', () => {
expect(render({'{{""}}': 'bar'})).toEqual({});
expect(render({'{{\'\'}}': 'bar'})).toEqual({});
expect(render({ "{{spreadValue()}}": { foo: "bar" } })).toEqual({foo: "bar"});
expect(render({ "{{ spreadValue() }}": { foo: "bar" } })).toEqual({foo: "bar"});
expect(render({ " {{ spreadValue() }} ": { foo: "bar" } })).toEqual({foo: "bar"});
});
it('recursive templates should work', () => {
const json = { foo: 'bar', bar: 'foo' };
Expand Down

0 comments on commit 4141096

Please sign in to comment.