diff options
Diffstat (limited to 'src/background/completion/impl/BookmarkRepositoryImpl.ts')
-rw-r--r-- | src/background/completion/impl/BookmarkRepositoryImpl.ts | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/background/completion/impl/BookmarkRepositoryImpl.ts b/src/background/completion/impl/BookmarkRepositoryImpl.ts index 3b80b93..2bc779d 100644 --- a/src/background/completion/impl/BookmarkRepositoryImpl.ts +++ b/src/background/completion/impl/BookmarkRepositoryImpl.ts @@ -1,5 +1,5 @@ -import BookmarkRepository, {BookmarkItem} from "../BookmarkRepository"; -import {HistoryItem} from "../HistoryRepository"; +import BookmarkRepository, { BookmarkItem } from "../BookmarkRepository"; +import { HistoryItem } from "../HistoryRepository"; import PrefetchAndCache from "./PrefetchAndCache"; const COMPLETION_ITEM_LIMIT = 10; @@ -8,7 +8,7 @@ export default class CachedBookmarkRepository implements BookmarkRepository { private bookmarkCache: PrefetchAndCache<BookmarkItem>; constructor() { - this.bookmarkCache = new PrefetchAndCache(this.getter, this.filter, 10,); + this.bookmarkCache = new PrefetchAndCache(this.getter, this.filter, 10); } queryBookmarks(query: string): Promise<BookmarkItem[]> { @@ -16,10 +16,10 @@ export default class CachedBookmarkRepository implements BookmarkRepository { } private async getter(query: string): Promise<BookmarkItem[]> { - const items = await browser.bookmarks.search({query}); + const items = await browser.bookmarks.search({ query }); return items - .filter(item => item.title && item.title.length > 0) - .filter(item => item.type === 'bookmark' && item.url) + .filter((item) => item.title && item.title.length > 0) + .filter((item) => item.type === "bookmark" && item.url) .filter((item) => { let url = undefined; try { @@ -27,20 +27,23 @@ export default class CachedBookmarkRepository implements BookmarkRepository { } catch (e) { return false; } - return url.protocol !== 'place:'; + return url.protocol !== "place:"; }) .slice(0, COMPLETION_ITEM_LIMIT) - .map(item => ({ + .map((item) => ({ title: item.title!!, url: item.url!!, })); } private filter(items: HistoryItem[], query: string) { - return items.filter(item => { - return query.split(' ').every(keyword => { - return item.title.toLowerCase().includes(keyword.toLowerCase()) || item.url!!.includes(keyword) + return items.filter((item) => { + return query.split(" ").every((keyword) => { + return ( + item.title.toLowerCase().includes(keyword.toLowerCase()) || + item.url!!.includes(keyword) + ); }); - }) - }; + }); + } } |