all handlers (handling calculation on data).
Methods
# static exports.filterHandler(data, keyword) → {array}
Filter the data according to the filter keyword.
Filtering is not sensitive to case but do not use a normalizer function for accent or hyphens.
Return unmodified data if keyword is empty.
Has an exact search behavior for parts of the string being between double quotes.
Builds the searchingKeywords array by spliting the string :
1) according to double quote to isolate fragment inside and outside of double quotes.
2) splitting the fragment outside of double quote according to spaces.
Then make the fitlering research according to all elements of the searchingKeyword array.
Parameters:
Name | Type | Description |
---|---|---|
data |
array | the data to filter. |
keyword |
string | the keyword string use to filter. |
the filtered data according to keyword.
array
# static exports.pagingHandler(data, currentPage, itemsPerPage) → {array}
Filter the data to return the items corresponding to the current page.
Returns unmodified data if there is less items than itemsPerPage value.
Parameters:
Name | Type | Description |
---|---|---|
data |
array | the data to paginate |
currentPage |
number | the currently selected page to display. |
itemsPerPage |
number | the number of items for each page. |
the data corresponding to the page to display.
array
# static exports.sortHandler(data, currentSort) → {array}
Sort the data according to currentSort parameter.
Returns unmodified data if there is no key selected (null).
Sorts the data according to the key parameter, and use the type parameter to define which sort to apply (number, string or date).
Have some checks to assert if the value suits required format, if not it is pushed to end of sort.
Parameters:
Name | Type | Description |
---|---|---|
data |
array | the data to paginate. |
currentSort |
object | the sorting parameter with a key, a direction and a type. |
the sorted data.
array