Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 15x 28x 72x 59x 28x | /** * Filters [items] based on a given [searchTerm]. * Catagories with no items after filtering are not included in the returned object. * @param {Object} allItems - { <categoryName>: [{ name, id }] } * @param {String} searchTerm * @returns {Object} */ export function filterItems(allItems, searchTerm) { return Object.entries(allItems) .map(([key, items]) => ({ text: key, options: items .filter((item) => item.name.toLowerCase().includes(searchTerm)) .map((item) => ({ text: item.name, value: item.key, })), })) .filter((group) => group.options.length > 0); } |