UNPKG

nested-fuzzy-search

Version:

[![npm version](https://badge.fury.io/js/nested-fuzzy-search.svg)](https://www.npmjs.com/package/nested-fuzzy-search) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

47 lines (43 loc) 1.14 kB
import { searchInArray, searchInArrayStream, searchInObject, searchInObjectStream, } from "./utils/index.js"; // Main search function function search( data, query, options = { threshold: 0.6, outputMode: "flat", excludeKeys: [], exact: false, } ) { const { threshold, outputMode, excludeKeys, exact } = options; if (Array.isArray(data) && outputMode === "tree") { return searchInArray(data, query, { threshold, excludeKeys, exact }); } else if (data && typeof data === "object") { return searchInObject(data, query, { threshold, excludeKeys, exact }); } return []; } async function* searchStream( data, query, options = { threshold: 0.6, outputMode: "flat", excludeKeys: [], exact: false, } ) { const { threshold, outputMode, excludeKeys, exact } = options; if (Array.isArray(data) && outputMode === "tree") { yield* searchInArrayStream(data, query, { threshold, excludeKeys, exact }); } else if (data && typeof data === "object") { yield* searchInObjectStream(data, query, { threshold, excludeKeys, exact }); } } export { search, searchStream };