Filter

April 11, 2019 ยท View on GitHub

The filter service allows you to register new filter and use them to format given values for user display or for integration with other services.

The filters listed in the filters service are the ones used by the 'data-ls-echo' view internally.

API

add()

Register a new filter

ParamTypeDescription
namestringName of the new filter
callbackcallableFilter function that accept the user value and return the new one

Return Value

Returns filter object instance.

Example

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

apply()

Applies a filter function on a given value

ParamTypeDescription
namestringName of the filter
valuemixedValue to format

Return Value

Filter callback result.

Example

let result = filter.apply('john doe', 'uppercase'); // JOHN DOE

Predefined Filters

NameDescription
uppercaseConvert given string to upper case letters
lowercaseConvert given string to lower case letters

Think we should add more predefined filters? send us a pull request or open an issue for us to review.