Expression

April 11, 2019 ยท View on GitHub

The expression service parses Litespeed.js template syntax.

The main use for this service is to bind service value into views and view components like 'data-ls-echo' and 'data-ls-if' rely on it heavily.

The expression parser detects service path references, evaluate them and parses the final results.

Litespeed.js expression also supports 'mustache' or 'twig' like filters to give a lot more flexibility and power.

API

parse()

Parses a Litespeed.js expression.

ParamTypeDescription
stringstringExpression string. Use {{object.path}} to evaluate a service path or add a pipe to apply a filter {{object.path
defstringDefault value to use when expression has evaluated with empty result (optional)

Return Value

Resulted expression string or def parameter value if empty result.

Example

conatiner.set('user', {
    'name': 'john doe',
    'email': 'john@example.com'
}, true, true);

filter.add('uppercase', function (value) {
    return value.toUpperCase();
});

let name = expression.parse('hello {{user.name|uppercase}}'); // hello JOHN DOE
let empty = expression.parse('your age is {{user.age|uppercase}}', 30); // your age is 30