/h2array

Create compact array trees resembling h() calls

Primary LanguageJavaScript

h2array

['header', [
  ['h1', 'hello world'],
  ['nav', [
    ['a', { href: '/foo' }, 'foo'],
    ['a', { href: '/bar' }, 'bar'],
    ['a', { href: '/baz' }, 'baz']
  ]]
]]

This module provides a variant of h() for storing calls as arrays, allowing you to serialize them as JSON for later use.

usage

NPM

h(tag, attributes?, children?)

Stores tag, attributes, and children in an array. Handles any missing arguments according to hyper2/h2spec.

> const h = require('h2array')
> h('h1', 'hello world')
['h1', null, 'hello world']

convert(h, node)

Applies h to node and all its children.

> const convert = require('h2array/convert')
> const h2ml = require('h2ml')
> const tree = ['h1', { style: 'color: red' }, 'hello world']
> convert(h2ml, tree)
"<h1 style='color: red'>hello world</h1>"