Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] improve options type #76

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/search.ts
mlbonniec marked this conversation as resolved.
Show resolved Hide resolved
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;
}
Loading