Files
markone/packages/core/src/collection.ts

37 lines
820 B
TypeScript

import type { Bookmark } from "./bookmark.js"
interface Collection {
id: string
name: string
description: string
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 }