LinkTemplate. LinkTemplate

A class representing the a template that can be used to render links.

Constructor

new LinkTemplate(templateString, filtersopt)

Parameters:
NameTypeAttributesDefaultDescription
templateStringstring

A Moustache template string.

filtersArray<optional>
[]

An optional array of filter functions. Each element in the array should itself be an array where the first element is a string specifying which fields the filter should be applied to (one of 'all', 'url', 'text', or 'description'), and the second the filter function itself which should be a function that takes a single string as an argument and returns a filtered version of that string.

Members

templateString

Get the template string.

templateString

Set the template string. Should be in Mustache format. All values passed will be coerced to strings.

Methods

addFilter(fieldName, filterFn) → {LinkTemplate}

Add a filter to be applied to one or all fields.

If an invalid args are passed, the function does not save the filter or throw an error, but it does log a warning.

Parameters:
NameTypeDescription
fieldNamestring

One of 'all', 'url', 'text', or 'description'.

filterFnfunction

the filter function.

Returns:

Returns a reference to self to facilitate function chaining.

Type: 
LinkTemplate

filtersFor(fieldName) → {Array.<function()>}

A function get the filter functions that should be applied to any given field.

Parameters:
NameTypeDescription
fieldNamestring

one of 'url', 'text', or 'description'.

Returns:

returns an array of callbacks, which may be empty. An empty array is returned if an invalid field name is passed.

Type: 
Array.<function()>