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

@rewired/h

v1.1.0

Published

Generate HTML from javascript array structures

Downloads

2

Readme

h

generate HTML from javascript array structures

like hyperscript but with arrays instead of functions. runs easily on the server and web workers, without a HtmlElement polyfil.

Example


var toHTML = require('h')

toHTML(
  ['div#page',
    ['div#header',
      ['h1.classy', 'h')),
    ['div#menu', { style: 'float: left, width: 200px' } },
      ['ul',
        ['li', 'one'],
        ['li', 'two'],
        ['li', 'three']]],
    ['div#content', {style: 'float: left;' },
      ['h2', 'content title'],
      ['p', 
        "so it's just like a templating engine,\n",
        "but easy to use inline with javascript\n"],
      ['p', 
        "the intension is for this to be used to create\n",
        "reusable, interactive html widgets. "]]]
)

toHTML (ary, options)

Create some html from an array structure. If the first element in the array is a string, that's the tag name. if it is an array of arrays, each item is mapped through toHTML and the results are concatenated.

Options

  • options.verbose -- print console.log output when true (default: false)

classes & id

If the tag name is of form name.class1.class2#id that is a short cut for setting the class and id.

attributes

If an {} object is passed in, it's values will be used to set attributes.

h('a', {href: 'https://npm.im/h'}, 'h')

html attributes names must be alphanumeric but may have hypens. attribute values will be escaped with html-escape.

innerHTML: non-escaped html content.

sometimes it is necessary to output non-escaped html, for example, rendered markdown, or the output of another templating library. to do this, use the {innerHTML:html} attribute. Note, this will cause any following children to be ignored.

children - string

If an argument is a string, it will be escaped with html-escape

children - null.

This is just ignored.

children - Array

Each item in the array is treated like a ordinary child. (string or HTMLElement) this is uesful when you want to iterate over an object:

['table',
  Object.keys(obj).map(function (k) {
    return ['tr'
      ['th', k],
      ['td', obj[k]]
    ]
  }]

License

MIT