Skip to content

Commit

Permalink
Merge pull request #76 from mlbonniec/73-improve-options-type
Browse files Browse the repository at this point in the history
[feature] improve options type
  • Loading branch information
SMAKSS authored Apr 8, 2024
2 parents 211f400 + e9a231a commit f2161cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { recursiveSearch } from './search-functions';
/**
* Searches for items within a collection that match the given search text.
*
* @param {Partial<SearchOptions>} 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.
*
Expand All @@ -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<SearchOptions>): SearchItem[] {
}: SearchOptions): SearchItem[] {
const regex = new RegExp(exact ? `^${searchText}$` : searchText, 'i');
const results: SearchItem[] = [];

Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type SearchItem = Record<string, any>;
export interface SearchOptions {
searchText: string;
searchItems: SearchItem | SearchItem[];
keys: string[];
include: boolean;
exact: boolean;
keys?: string[];
include?: boolean;
exact?: boolean;
}

0 comments on commit f2161cd

Please sign in to comment.