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

thing-to-html

v1.0.7

Published

Convert objects & arrays to HTML!

Downloads

5

Readme

Thing To HTML

Convert JavaScript objects and arrays to HTML!

thingToHTML will take an object or an array (no matter how deeply nested) and create an HTML structure on you're page that is collapsible at each level - similar to what the JSONview plugin for Chrome does for JSON objects. Optionally, you can have it create a collapse / un-collapse all button at the top of the generated tree. Objects do not need to be JSON, meaning that double-quotes are not needed for everything (ugly!), and property values can be functions. There are two themes supplied, light & dark, for your syntax-viewing pleasure :).

Live Preview

Installation

via NPM

npm install thing-to-html

Include thing.css in your page's <head>:

<head>
  ...
  <link rel="stylesheet" href="node_modules/thing-to-html/thing.css">
</head>

Include thingToHTML.js just before your closing <body> tag:

<body>
  ...
  <script src="node_modules/thing-to-html/thingToHTML.js"></script>
</body>

Manually

Download thing.css and thingToHTML.js.

Include thing.css in your page's <head>:

<head>
  ...
  <link rel="stylesheet" href="thing.css">
</head>

Include thingToHTML.js just before your closing <body> tag:

<body>
  ...
  <script src="thingToHTML.js"></script>
</body>

Usage

thingToHTML({
  thing: <{an: object} OR [an, array]>,
  container: '.any-css-selector',
  button: true, // optional
  theme: 'dark' // optional - 'dark' or 'light'
});

thingToHTML takes an object as its only argument with 2 necessary properties (thing, container) and 2 optional properties (button, theme).

thing

An object or an array. The fun starts when you have deeeeeeply nested objects & arrays.

{some: 'Object'} or ['some', 'array']

container

Any valid CSS selector as a string. thingToHTML will use document.querySelector to grab it.

Example selectors:

  • '.some-class'
  • '#some-id'
  • 'body'
  • '.some-class .in-another-class'
  • etc...

button

This property is optional. Pass in true if you would like to generate the "Collapse / Un-Collapse All" button, omit it if not. The button will toggle all levels of your object to be open or closed.

theme

This property is optional. There are two themes supplied in the CSS file: 'light' and 'dark'. Pass one in to get that theme (see examples below) or omit this property altogether for no styling. The themes will provide syntax highlighting for everything except functions.

Examples

Object example

var myObject = {
  string: 'This is a string.',
  boolean: true,
  null: null,
  undefined: undefined,
  numbers: 1234567890,
  url: 'https://github.com/qodesmith',
  email: '[email protected]',
  array: ['one', 'two', 'three'],
  object: {property: 'value'},
  singleLineFxn: function() { return 'I am a single-line function!'; },
  multiLineFxn: function() {
    var x = ['Notice', 'how', 'your', 'indentation', 'is', 'preserved?'];
    x.map(function(word) {
      console.log(word);
    });

    return 'Awesome';
  },
  arrayOfObjects: [
    {arrays: 'can', be: 'nested'},
    {as: 'deep', as: ['you', {would: 'like'}]},
    {this: {reminds: {me: {of: 'Inception'}}}}
  ]
};

thingToHTML({
  thing: myObject,
  container: '#some-id',
  button: true,
  theme: 'dark'
});

This renders out on the screen like this (dark theme):

Open

some alt text here

Closed

some alt text here

Array example

var myArray = [
  'Various types have CSS styling for syntax highlighting.',
  'Functions are the only types not syntax highlighted',
  function singleLine() { return 'This is a single line function.' },
  function multiLine() {
    var line1 = 'This is a multi-line function ';
    var line2 = 'in an array.';
    return line1 + line2;
  },
  {numbers: 1234567890, moreNumbers: 0987654321},
  {this: {obj: {can: {be: {nested: ['like', 'crazy', {deep: undefined}]}}}}},
  ['array', ['within', 'arrays'], ['within' ['more', 'arrays']]]
];

thingToHTML({
  thing: myArray,
  container: '.some-class',
  button: true,
  theme: 'light'
});

This renders out on the screen like this (dark theme):

Open

some alt text here

Closed

some alt text here

Contact

Questions? Comments? Issues? Feature requests?

I'm all ears...