litespeed.js
Version:
Lite & fast micro javascript framework that is easy to learn
60 lines (38 loc) • 1.3 kB
Markdown
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](/docs/views/echo.md)' view internally.
- [add(name, callback)](
- [apply(name, value)](
Register a new filter
Param | Type | Description
--- | --- | ---
**name** | string | Name of the new filter
**callback** | callable | Filter function that accept the user value and return the new one
Returns filter object instance.
```js
filter.add('uppercase', function (value) {
return value.toUpperCase();
});
```
Applies a filter function on a given value
Param | Type | Description
--- | --- | ---
**name** | string | Name of the filter
**value** | mixed | Value to format
Filter callback result.
```js
let result = filter.apply('john doe', 'uppercase'); // JOHN DOE
```
Name | Description
--- | ---
**uppercase** | Convert given string to upper case letters
**lowercase** | Convert 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.