Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ const parseString = (() => {
value = parameter.defaultValue;
}

if (typeof value === 'function') {
return value();
}

if (typeof value === 'object') {
return value;
}
Expand Down
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ describe('json-template', () => {
});
});

// This section tests that the parse function applies the templating
// on string with function
describe('function', () => {
it('should compute template with function', () => {
const template = parse(['{{userCard}}']);
assert.deepEqual(template.parameters, [{ key: 'userCard' }]);
assert.deepEqual(template({ userCard: () => ({ id: 1, user: "John" }) }), [{ id: 1, user: "John" }]);
});
});

// This section tests that arbitrary types may be present
// as leaf nodes of the object tree, and they are handled correctly.
describe('unknown types', () => {
Expand Down