Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zorapeteri/bookmarks-to-json
Convert browser-exported HTML bookmarks to JSON format
https://github.com/zorapeteri/bookmarks-to-json
Last synced: about 1 month ago
JSON representation
Convert browser-exported HTML bookmarks to JSON format
- Host: GitHub
- URL: https://github.com/zorapeteri/bookmarks-to-json
- Owner: zorapeteri
- License: mit
- Created: 2021-09-05T14:28:00.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-09T12:59:40.000Z (over 1 year ago)
- Last Synced: 2024-10-13T14:13:12.483Z (3 months ago)
- Language: JavaScript
- Homepage: https://zorapeteri.github.io/bookmarks-to-json/
- Size: 319 KB
- Stars: 27
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bookmarks-to-json
bookmarksToJSON is a no-dependecy, Regex-based pure JS function that takes in the HTML-style code of the bookmarks files exported by browsers like Chrome and Firefox, and converts them into JSON / JS object format with a recursive tree structure.
Bookmarks, folders and subfolders are nested using a `children` property on the folders.
## usage
`npm i bookmarks-to-json`
```js
import fs from 'fs'
import { bookmarksToJSON } from 'bookmarks-to-json'const content = fs.readFileSync('bookmarks.html', 'utf-8')
const options = {
formatJSON: true, // return prettified JSON - false by default
spaces: 2 // number of spaces to use for indentation - 2 by default
}
fs.writeFileSync('bookmarks.json', bookmarksToJSON(content, options))
``````json
bookmarks.json[
{
"type": "link",
"addDate": 1630524312,
"title": "GitHub",
"url": "https://github.com/"
},
{
"type": "folder",
"addDate": 1630524192,
"lastModified": 1630524211,
"title": "Bookmarks bar",
"children": [
{
"type": "link",
"addDate": 1630524211,
"title": "Lettuce",
"url": "https://www.youtube.com/watch?v=M9PAXeKHw7Q"
}
]
}
]
``````js
import fs from 'fs'
import { bookmarksToJSON } from 'bookmarks-to-json'const content = fs.readFileSync('bookmarks.html', 'utf-8')
const options = { stringify: false } // returns JS object, not stringified JSON
console.log(bookmarksToJSON(content, options).map(({ title, type }) => ({ title, type })))// [
// { title: 'GitHub', type: 'link' },
// { title: 'Bookmarks bar', type: 'folder' },
// ]
```