Strings.template()

Render some data into a template string.

Uses Lodash template syntax (e.g. `<%= %>`, `<%- %>`, `<% %>`) Also provides access to the Node.js core utility module (as `util`), as well as Lodash itself (as `_`).

Usage

Hover over inputs/exits for more info.

var Strings = require('machinepack-strings');


// Render some data into a template string.

Strings.template({

templateStr: 'Hi there, Miss <%= me.lastName %>!',

data: {},

}).execSync();

Inputs

templateStr required

The string to use as a template.

'Hi there, Miss <%= me.lastName %>!'
data

A dictionary of data which will be accessible from the template.

{}

Exits

error

An unexpected error occurred.

missingData

One or more variables used in the template were not provided in the template data.

{ message: 'Some variables (`me`,`friends`) were used in template "/code/machine/docs/.type-table.tpl", but not provided in the template data dictionary.',
  missingVariables: [ 'me' ] }
couldNotRender

Could not render the template due to invalid or unparseable syntax.

success

OK.

'Hi there, Miss Piggy!'