UNPKG

@grafana/ui

Version:
41 lines (36 loc) 1.23 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var fuzzy = require('./fuzzy.cjs'); "use strict"; var SearchFunctionType = /* @__PURE__ */ ((SearchFunctionType2) => { SearchFunctionType2["Word"] = "Word"; SearchFunctionType2["Prefix"] = "Prefix"; SearchFunctionType2["Fuzzy"] = "Fuzzy"; return SearchFunctionType2; })(SearchFunctionType || {}); const wordSearch = (items, text) => { return items.filter((c) => (c.filterText || c.label).includes(text)); }; const prefixSearch = (items, text) => { return items.filter((c) => (c.filterText || c.label).startsWith(text)); }; const fuzzySearch = (items, text) => { text = text.toLowerCase(); return items.filter((item) => { const { distance, ranges, found } = fuzzy.fuzzyMatch(item.label.toLowerCase(), text); if (!found) { return false; } item.sortValue = distance; item.highlightParts = ranges; return true; }); }; const SearchFunctionMap = { ["Word" /* Word */]: wordSearch, ["Prefix" /* Prefix */]: prefixSearch, ["Fuzzy" /* Fuzzy */]: fuzzySearch }; exports.SearchFunctionMap = SearchFunctionMap; exports.SearchFunctionType = SearchFunctionType; //# sourceMappingURL=searchFunctions.cjs.map