Multi-format parser for your bookmarking backups. Heavily tested with popular browsers (Chrome, Firefox, Safari) and also bookmarking services (Pocket, Pinboard). This is the library Kozmos uses for importing user bookmarks.
Supported Formats:
Format | Timestamps? | Tags? |
---|---|---|
Netscape | Yes | * |
Yes | Yes | |
Pinboard | Yes | Yes |
Chrome/Firefox (JSON) | Yes | Yes |
JSON | ** | ** |
Txt | *** | Nope |
* Netscape formats have folders instead of tags. This library generates tags from the folder names hierarchically.
** JSON files has to be structured as an array and also use common property names.
*** Timestamps can be extracted from txt
files only if URL and timestamp is in the same line.
$ npm install kozmos/bookmark-backup-parser
const parse = require('bookmark-backup-parser')
const html = require('fs').readFileSync('./bookmarks.html').toString()
const parsed = parse(html)
// [
// { title: "Kozmos", url: "http://kozmos.cool", addedAt: 1501384533000, tags: ['foo', 'bar'] },
// ...
// ]
It's safer to use this library inside a web worker. You can either webworkerify it, or you can generate a web worker bundle in this repo, so you can save some bytes from your app bundle.
Generate the web worker bundle, clone this repo and run make create-worker
:
$ git clone git@github.com:kozmos/bookmark-backup-parser.git
$ cd bookmark-backup-parser
$ npm install
$ make create-worker
This will save the worker bundle to dist/worker.js
. Copy that to a public
folder in your app where you can access in production, and call it from your app
like in the below example:
const worker = new Worker('/public/backup-parsing-worker.js')
worker.onmessage = function (event) {
// It'll respond you with the result
console.log(event.data.result)
}
worker.onerror = function (event) {
// This gets called when there is an error
console.error(event.error)
}
// Send a message to the worker with `input` property. It has to be a string.
worker.postMessage({
input: "..."
})