hyper-json

an abstract datatype compatible with the hyperscript API

Usage no npm install needed!

<script type="module">
  import hyperJson from 'https://cdn.skypack.dev/hyper-json';
</script>

README

hyperjson

An abstract datatype compatible with the hyperscript API.

What's hyperscript?

Hyperscript is everything you need to know about a dom element to be able to recreate it. Instead of writing <h1>Hello!</h1> you write h('h1', 'Hello!').

Hyperscript works clientside and serverside, and there are now several other projects adhering to the same API.

What's hyperjson?

Hyperjson is an abstraction of the data component (the arguments passed to the h function) from the function itself. It is intended to be used clientside.

It provides two functions:

fromDOM(domElement)

Accepts any DOM element and returns JSON (HyperJSON) representing all the relevant attributes of that DOM element and its children.

callOn(hyperJSON, callback)

Accepts valid hyperjson and a callback which adheres to the Hyperscript API:

function myCallback (tagType, attributes, children) {
    /* your code here */
};

The most prominent examples of callbacks are hyperscript and virtual-hyperscript, which produce DOM elements or virtual-DOM elements, respectively.

You can create custom plugins for filtering or modifying elements, or for producing alternative data structures that adhere to a similar structure.