From 9e47c12a1665d4411631feb956fc8b1904f69c63 Mon Sep 17 00:00:00 2001 From: Mathis Le Bonniec Date: Sun, 7 Apr 2024 19:37:23 +0200 Subject: [PATCH 1/2] feat(generics): SearchItem has been wrapped into a generic type --- src/search.ts | 6 +++--- src/types.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/search.ts b/src/search.ts index e337593..f8ce25b 100644 --- a/src/search.ts +++ b/src/search.ts @@ -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; } From e9a231a0bcbc92e5948960474df4baefd97fb85b Mon Sep 17 00:00:00 2001 From: Mathis Le Bonniec Date: Mon, 8 Apr 2024 22:17:30 +0200 Subject: [PATCH 2/2] docs(jsdoc): remove Partial type from options --- src/search.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search.ts b/src/search.ts index f8ce25b..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. *