https://github.com/jamen/h2array
Create compact array trees resembling h() calls
https://github.com/jamen/h2array
Last synced: 3 months ago
JSON representation
Create compact array trees resembling h() calls
- Host: GitHub
- URL: https://github.com/jamen/h2array
- Owner: jamen
- Created: 2017-06-10T22:43:45.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-09-24T10:18:01.000Z (over 4 years ago)
- Last Synced: 2025-09-25T01:31:08.535Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 7
- Watchers: 0
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# h2array
```js
['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
[](https://www.npmjs.com/package/h2array)
### `h(tag, attributes?, children?)`
Stores `tag`, `attributes`, and `children` in an array. Handles any missing arguments according to [`hyper2/h2spec`](https://github.com/hyper2/h2spec).
```js
> const h = require('h2array')
> h('h1', 'hello world')
['h1', null, 'hello world']
```
### `convert(h, node)`
Applies `h` to `node` and all its children.
```js
> const convert = require('h2array/convert')
> const h2ml = require('h2ml')
> const tree = ['h1', { style: 'color: red' }, 'hello world']
> convert(h2ml, tree)
"
hello world
"
```