/likedb

Offline bookmarking DB that syncs with Kozmos servers

Primary LanguageTypeScript

likedb

Offline bookmarking database with auto-sync to Kozmos.

Install

$ yarn add kozmos/likedb

Manual

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.

.add

Create a new bookmark:

await likedb.add({ title: "Wikipedia", url: "https://en.wikipedia.org" })

.count

Get number of total bookmarks saved:

await likedb.count()

.delete

Delete a bookmark by URL:

await likedb.delete("https://en.wikipedia.org")

.get

Get a bookmark by URL:

const bookmark = await likedb.get("https://en.wikipedia.org")

.listByTag

const result = await likedb.listByTag("foobar")

.recent

List recently added bookmarks. Requires a limit parameter.

const last10bookmarks = await likedb.recent(10)

.searchByTags(keyword, { offset: 0, limit: 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"]

.searchByTitle(keyword, { offset: 0, limit: 10 })

Returns bookmarks with title matching given keyword.

const results = await likedb.searchByTitle("wik")

results[0].title
// => Wikipedia

.searchByUrl(keyword, { offset: 0, limit: 10 })

Returns bookmarks with url matching given keyword.

const results = await likedb.searchByUrl("you")

results[0].url
// => https://youtube.com

Tests

Run unit tests (open localhost:7559 to see results on web browser):

$  node test/likedb.js -b
$  node test/scheduler.js -b