@react-md/utils
Version:
General utils for react-md.
28 lines • 1.29 kB
JavaScript
import { defaults } from "../defaults";
import { DEFAULT_SEARCH_OPTIONS, getSearchString } from "./utils";
/**
* Filters a list by ensuring that all items contain the query string in order
* anywhere in it's own value.
*
* @param query - The current query string
* @param searchable - The list of searchable items that should be filtered
* @param options - All the search options to use
* @returns A filtered list of all the searchable items based on the query
* string.
*/
export function caseInsensitiveFilter(query, searchable, options) {
if (options === void 0) { options = {}; }
var _a = defaults(options, DEFAULT_SEARCH_OPTIONS), getItemValue = _a.getItemValue, valueKey = _a.valueKey, trim = _a.trim, ignoreWhitespace = _a.ignoreWhitespace, _b = _a.startsWith, startsWith = _b === void 0 ? false : _b;
query = getSearchString(query, true, trim, ignoreWhitespace);
if (!query || !searchable.length) {
return searchable;
}
return searchable.filter(function (item) {
var value = getSearchString(getItemValue(item, valueKey), true, trim, ignoreWhitespace);
if (startsWith) {
return value.indexOf(query) === 0;
}
return value.indexOf(query) !== -1;
});
}
//# sourceMappingURL=caseInsensitiveFilter.js.map