Offline bookmarking database with auto-sync to Kozmos.
$ yarn add kozmos/likedb
Initialize a new database and hook it with Kozmos to get it synced automatically;
import LikeDB from 'likedb'
import syncWithKozmos from 'likedb/lib/kozmos'
const likedb = new LikeDB()
const sync = syncWithKozmos(likedb, {
apiKey: "kozmos-api-key",
apiSecret: "kozmos-api-secret"
onPostUpdates: updates => console.log("Posted updates: ", updates),
onReceiveUpdates: updates => console.log("Received updates: ", updates)
})
That's it. Now you have a bookmarking database based on indexeddb, and it'll auto-sync to Kozmos.
Create a new bookmark:
await likedb.add({ title: "Wikipedia", url: "https://en.wikipedia.org" })
Get number of total bookmarks saved:
await likedb.count()
Delete a bookmark by URL:
await likedb.delete("https://en.wikipedia.org")
Get a bookmark by URL:
const bookmark = await likedb.get("https://en.wikipedia.org")
const result = await likedb.listByTag("foobar")
List recently added bookmarks. Requires a limit parameter.
const last10bookmarks = await likedb.recent(10)
Returns bookmarks with tags matching given keyword. For example, if a bookmark is tagged by foobar
,
it'll return for search term such as fo
;
const results = await likedb.searchByTags("fo")
results[0].tags
// => ["foobar"]
Returns bookmarks with title matching given keyword.
const results = await likedb.searchByTitle("wik")
results[0].title
// => Wikipedia
Returns bookmarks with url matching given keyword.
const results = await likedb.searchByUrl("you")
results[0].url
// => https://youtube.com
Run unit tests (open localhost:7559
to see results on web browser):
$ node test/likedb.js -b
$ node test/scheduler.js -b