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

listtojson

v0.0.6

Published

An npm module for node.js to convert HTML lists to JSON objects

Downloads

9,285

Readme

NPM

Build Coverage Status Dependencies Known Vulnerabilities

listtojson

An npm module for node.js to convert HTML lists to JSON objects. Basically ordered and unordered lists are the same. Just the browser treats them differently in rendering bullets or numbers I decided to not differenciate between them and just provide a package for all of them.

This package can be passed the markup for a single list as a string, a fragment of HTML or an entire page or just a URL (with an optional callback function; promises also supported).

The response is always an array. Every array entry in the response represents a list found on the page (in same the order they were found in the HTML).

Basic Usage

Install via npm

npm install listtojson

Remote (convertUrl)

'use strict';

const listtojson = require('listtojson');

listtojson.convertUrl(
    'https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes',
    function(listsAsJson) {
        console.log(listsAsJson[1]);
    }
);

Local (convert)

Have a look in the tests folder.

'use strict';

const listtojson = require('../lib/listtojson');
const fs = require('fs');
const path = require('path');

const html = fs.readFileSync(path.resolve(__dirname, '../test/lists.html'), {encoding: 'UTF-8'});
const converted = listtojson.convert(html);

console.log(converted);

Options

request (only convertUrl)

If you need to get data from a remote server to pass it to the parser you can call listtojson.convertUrl. When working behind a proxy you can pass any request-options (proxy, headers,...) by adding a request object to the options passed to convertUrl. for more information on how to configure request please have a look at: https://github.com/request/request

listtojson.convertUrl('https://www.timeanddate.com/holidays/ireland/2017', {
    useFirstRowForHeadings: true,
    request: {
        proxy: 'http://proxy:8080'
    }
});

containsClasses

Array of classes to find a specific list using this css class. Default is 'null/undefined'.

id

The id of the list which is to be fetched provided as a string. Default is 'null/undefined'.

Contributing

Improvements, fixes and suggestions for better written modules that other people have created are welcome, as are bug reports against specific tables it is unable to handle.

You can find basic tests in the test folder. I implemented the most straight forward way in using the library. Nonetheless there are some edge cases that need to be tested and I would like to ask for support here. Feel free to fork and create PRs here. Every bit of help is appreciated.

If you submit a pull request, please add an example for your use case, so I can understand what you want it to do (as I want to get around to writing tests for this and want to understand the sort of use cases people have).