implement bookmark collections and enhance bookmark search functionality
This commit is contained in:
@@ -7,4 +7,30 @@ interface Collection {
|
||||
bookmarks: Bookmark[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds bookmarks in a collection that match the given criteria
|
||||
* @param collection The collection to search in
|
||||
* @param options Optional search criteria
|
||||
* @returns Array of matching bookmarks
|
||||
*/
|
||||
function findCollectionBookmarks(
|
||||
collection: Collection,
|
||||
options?: {
|
||||
searchTerm?: string
|
||||
}
|
||||
): Bookmark[] {
|
||||
if (!options?.searchTerm) {
|
||||
return collection.bookmarks
|
||||
}
|
||||
|
||||
const searchTerm = options.searchTerm.toLowerCase()
|
||||
return collection.bookmarks.filter((bookmark) => {
|
||||
return (
|
||||
bookmark.title.toLowerCase().includes(searchTerm) ||
|
||||
bookmark.url.toLowerCase().includes(searchTerm)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export type { Collection }
|
||||
export { findCollectionBookmarks }
|
||||
|
Reference in New Issue
Block a user