npm package: @insidiousfiddler/bookmarks2data
Description: A Node.js package to convert browser-exported bookmarks into various formats
Author: Vahn Gomes
Latest version: 0.1.1

# Bookmarks2Data

Bookmarks2Data is a Node.js package that allows you to easily convert browser-exported bookmarks into various formats such as lists, JSON, and CSV. With Bookmarks2Data, you can parse bookmark files in different formats and seamlessly convert them to your desired output format.

## Installation

To install Bookmarks2Data, you need to have Node.js installed on your system. Then, follow these steps:

1. Open your terminal or command prompt.
2. Navigate to your project directory.
3. Run the following command to install the package:

```bash
npm install bookmarks2data
```

## Usage

Using Bookmarks2Data in your Node.js project is straightforward. Here's an example of how to convert a browser-exported bookmark file to JSON:

```javascript
const { BookmarkParser, BookmarkConverter } = require("bookmarks2data");

// Path to your bookmark file
const bookmarkFilePath = "/path/to/bookmarks.html";

// Parse the bookmark file
const parser = new BookmarkParser();
const parsedBookmarks = parser.parseHTML(bookmarkFilePath);

// Convert parsed bookmarks to JSON
const converter = new BookmarkConverter();
const jsonBookmarks = converter.toJSON(parsedBookmarks);

// Print the JSON bookmarks
console.log(jsonBookmarks);
```

In the above code snippet, we first import the `BookmarkParser` and `BookmarkConverter` classes from the `bookmarks2data` package. Then, we specify the path to the bookmark file we want to convert. Next, we use the `BookmarkParser` class to parse the HTML bookmark file, and the resulting parsed bookmarks are passed to the `BookmarkConverter` class to convert them to JSON format. Finally, we print the JSON-formatted bookmarks.

## Configuration Options

Bookmarks2Data also provides configuration options to customize the conversion process. Here's an example of how to set the output file name:

```javascript
const { Config } = require("bookmarks2data");

// Set the output file name
const config = new Config();
config.setOutputFileName("my-bookmarks.json");
```

In the above code snippet, we import the `Config` class from the `bookmarks2data` package. Then, we create a new instance of the `Config` class and use the `setOutputFileName()` method to set the desired output file name to 'my-bookmarks.json'.

## Error Handling

Bookmarks2Data includes an `ErrorHandler` class to handle any errors that may occur during the parsing or conversion process. If an error occurs, the package provides meaningful error messages. Here's an example of how to handle parsing errors:

```javascript
const { BookmarkParser, ErrorHandler } = require("bookmarks2data");

// Path to your bookmark file
const bookmarkFilePath = "/path/to/bookmarks.html";

// Parse the bookmark file
const parser = new BookmarkParser();
const errorHandler = new ErrorHandler();

try {
  const parsedBookmarks = parser.parseHTML(bookmarkFilePath);
  // Continue with further processing
} catch (error) {
  errorHandler.handleParseError(error);
}
```

In the above code snippet, we import the `BookmarkParser` and `ErrorHandler` classes from the `bookmarks2data` package. We create a new instance of the `BookmarkParser` class and the `ErrorHandler` class. Inside a try-catch block, we attempt to parse the bookmark file using the `parseHTML()` method. If an error occurs, it will be caught, and the `handleParseError()` method of the `ErrorHandler` class will handle the error.

## Testing

Bookmarks2Data includes comprehensive unit tests to ensure its functionality and reliability. To run the tests, follow these steps:

1. Ensure that you have installed the package dependencies by running `npm install` in the root directory of the package.
2. Open your terminal or command prompt.
3. Navigate to the root directory of the package.
4. Run the following command to execute the tests:

```bash
npm test
```

The tests will run, and you will see the results in the console.

## Conclusion

Bookmarks2Data simplifies the process of converting browser-exported bookmarks into different formats such as lists, JSON, and CSV. With its intuitive API and configuration options, you can seamlessly integrate it into your Node.js projects.