diff --git a/src/search.ts b/src/search.ts index e337593..14cf887 100644 --- a/src/search.ts +++ b/src/search.ts @@ -4,7 +4,7 @@ import { recursiveSearch } from './search-functions'; /** * Searches for items within a collection that match the given search text. * - * @param {Partial} options - The search parameters including searchText, searchItems, keys to search in, + * @param {SearchOptions} options - The search parameters including searchText, searchItems, keys to search in, * whether to include keys and if the search is exact. * @returns {SearchItem[]} The matched items as an array. * @@ -31,12 +31,12 @@ import { recursiveSearch } from './search-functions'; * console.log(found); // [{ name: "John", lastName: "Doe" }] */ function search({ - searchText = '', - searchItems = [], + searchText, + searchItems, keys = [], include = true, exact = false -}: Partial): SearchItem[] { +}: SearchOptions): SearchItem[] { const regex = new RegExp(exact ? `^${searchText}$` : searchText, 'i'); const results: SearchItem[] = []; diff --git a/src/types.ts b/src/types.ts index f3ff9e8..ec37a20 100644 --- a/src/types.ts +++ b/src/types.ts @@ -26,7 +26,7 @@ export type SearchItem = Record; export interface SearchOptions { searchText: string; searchItems: SearchItem | SearchItem[]; - keys: string[]; - include: boolean; - exact: boolean; + keys?: string[]; + include?: boolean; + exact?: boolean; }