npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nbff-converter

v1.1.2

Published

Netscape Bookmark File Format Converter

Downloads

30

Readme

Netscape Bookmark File Format Converter

This is an independent, promise-based tool used for converting between Netscape Bookmark File Format and JSON.

Table of Contents

Features

Conversion options

  • NBFF (subfolder and shortcut item) --> JSON node (by default sorted into a JSON tree)
  • JSON tree --> NBFF (subfolder and shortcut item)

Configurability

  • Change created/expected JSON node property names
  • Pass a custom JSON node processing midFunction

Setup

Install

npm install nbff-converter

Import

const NBFFConverter = require('nbff-converter')

Usage

Default created/expected JSON node property names

#NBFFjsonModel = {
	CHILDREN: 'children',
	INNER_TEXT: 'title',
	HREF: 'url',
	ADD_DATE: 'dateAdded',
	LAST_VISIT: 'dateLastVisited',
	LAST_MODIFIED: 'dateModified',
	PERSONAL_TOOLBAR_FOLDER: 'personalToolbarFolder',
}

Create a converter

const nbffConverter = new NBFFConverter(yourNBFFjsonModel?)

Convert

  • NBFF to JSON

nbffConverter.netscapeToJSON(nbffString, midFunction?)
	.then((result) => console.log(result))
The midFunction parameter looks like:

(node: NBFFjsonModelNode) => void | any | Promise

Tip: When passing a method as midFunction, you can bind its this.
The values inside the Promise look like:

{ level: Number, id: Number, numOfNodes: Number, [NBFFjsonModel.CHILDREN]: Array }

  • JSON to NBFF

nbffConverter.jsonToNetscape(jsonTree, header?, tabSpaces?)
	.then((result) => console.log(result))
The values inside the Promise look like:

{ nbffStr: String, numOfNodes: Number }

Get NBFF header

let nbffHeader = nbffConverter.header

Result:

<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!--This is an automatically generated file.
	It will be read and overwritten.
	Do Not Edit! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<Title>Bookmarks</Title>
<H1>Bookmarks</H1>

Exception throwing

TypeError | ReferenceError | RangeError

Examples

Using the default NBFFjsonModel

dummy.html

<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!--This is an automatically generated file.
	It will be read and overwritten.
	Do Not Edit! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<Title>Bookmarks</Title>
<H1>Bookmarks</H1>
<DL><p>
    <DT><H3>dummy folder 1</H3>
    <DL><p>
        <DT><A HREF="http://dummyURL.dne">Does not exist</A>
        <DT><H3>dummy folder 2</H3>
        <DL><p>
            <DT><A HREF="http://dummyURL.idne">It does not exist</A>
        </DL><p>
    </DL><p>
    <DT><A HREF="http://dummyURL.sdne">Still does not exist</A>
    <DT><H3>dummy folder 3</H3>
    <DL><p>
        <DT><A HREF="http://dummyURL.nidne">No, it does not exist</A>
    </DL><p>
</DL><p>

convert-to-json.js

const fs = require('fs')
const NBFFConverter = require('nbff-converter')

const nbffString = fs.readFileSync('./dummy.html', 'utf8')
const nbffConverterDefault = new NBFFConverter()

nbffConverterDefault.netscapeToJSON(nbffString).then((result) => {
	fs.writeFileSync('result.json', JSON.stringify(result, null, 4))
})

// Simple midFunction example:
const myMidFunction = (node) => node.title

nbffConverterDefault.netscapeToJSON(nbffString, myMidFunction).then((result) => {
	fs.writeFileSync('myMidFunctionResult.json', JSON.stringify(result, null, 4))
})

result.json

{
    "level": 0,
    "id": 0,
    "numOfNodes": 7,
    "children": [
        {
            "level": 1,
            "id": 1,
            "type": "folder",
            "title": "dummy folder 1",
            "children": [
                {
                    "level": 2,
                    "id": 2,
                    "type": "url",
                    "url": "http://dummyURL.dne",
                    "title": "Does not exist"
                },
                {
                    "level": 2,
                    "id": 3,
                    "type": "folder",
                    "title": "dummy folder 2",
                    "children": [
                        {
                            "level": 3,
                            "id": 4,
                            "type": "url",
                            "url": "http://dummyURL.idne",
                            "title": "It does not exist"
                        }
                    ]
                }
            ]
        },
        {
            "level": 1,
            "id": 5,
            "type": "url",
            "url": "http://dummyURL.sdne",
            "title": "Still does not exist"
        },
        {
            "level": 1,
            "id": 6,
            "type": "folder",
            "title": "dummy folder 3",
            "children": [
                {
                    "level": 2,
                    "id": 7,
                    "type": "url",
                    "url": "http://dummyURL.nidne",
                    "title": "No, it does not exist"
                }
            ]
        }
    ]
}

myMidFunctionResult.json

{
    "level": 0,
    "id": 0,
    "numOfNodes": 7,
    "children": [
        "dummy folder 1",
        "Does not exist",
        "dummy folder 2",
        "It does not exist",
        "Still does not exist",
        "dummy folder 3",
        "No, it does not exist"
    ]
}

Using a custom NBFFjsonModel

dummy.json

{
    "contents": [
        {
            "name": "dummy folder 1",
            "contents": [
                { "shortcut": "http://dummyURL.dne", "name": "Does not exist" },
                {
                    "name": "dummy folder 2",
                    "contents": [
                        { "shortcut": "http://dummyURL.idne", "name": "It does not exist" }
                    ]
                }
            ]
        },
        { "shortcut": "http://dummyURL.sdne", "name": "Still does not exist" },
        {
            "name": "dummy folder 3",
            "contents": [
                { "shortcut": "http://dummyURL.nidne", "name": "No, it does not exist" }
            ]
        }
    ]
}

convert-to-nbff.js

const fs = require('fs')
const NBFFConverter = require('nbff-converter')

const jsonString = fs.readFileSync('./dummy.json', 'utf8')
const jsonData = JSON.parse(jsonString)

const myCustomModel = { CHILDREN: 'contents', INNER_TEXT: 'name', HREF: 'shortcut' }
const nbffConverterCustom = new NBFFConverter(myCustomModel)

nbffConverterCustom.jsonToNetscape(jsonData, true, 4).then((result) => {
	fs.writeFileSync('result.html', result.nbffStr)
})

result.html

<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!--This is an automatically generated file.
	It will be read and overwritten.
	Do Not Edit! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<Title>Bookmarks</Title>
<H1>Bookmarks</H1>
<DL><p>
    <DT><H3>dummy folder 1</H3>
    <DL><p>
        <DT><A HREF="http://dummyURL.dne">Does not exist</A>
        <DT><H3>dummy folder 2</H3>
        <DL><p>
            <DT><A HREF="http://dummyURL.idne">It does not exist</A>
        </DL><p>
    </DL><p>
    <DT><A HREF="http://dummyURL.sdne">Still does not exist</A>
    <DT><H3>dummy folder 3</H3>
    <DL><p>
        <DT><A HREF="http://dummyURL.nidne">No, it does not exist</A>
    </DL><p>
</DL><p>

Project Status

Project is: in progress

Room for Improvement

  • Support for other NBFF items?
  • Completely customizable item attribute names?

To do:

  • Other possible subfolder/shortcut attributes

Contact

Created by @kishtra - feel free to contact me!

License

This project is open source and available under the MIT License.