JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8313224
  • Score
    100M100P100Q212885F
  • License MIT

Hyperscript compatible DSL for creating virtual HAST trees

Package Exports

  • hastscript

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hastscript) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

hastscript Build Status Coverage Status

Hyperscript (and virtual-hyperscript) compatible DSL for creating virtual HAST trees.

Installation

npm:

npm install hastscript

hastscript is also available as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

Dependencies:

var h = require('hastscript');

AST:

var tree = h('.foo#some-id', [
    h('span', 'some text'),
    h('input', {
        'type': 'text',
        'value': 'foo'
    }),
    h('a.alpha', {
        'class': 'bravo charlie',
        'download': 'download'
    }, ['delta', 'echo'])
]);

Yields:

{ type: 'element',
  tagName: 'div',
  properties: { id: 'some-id', className: [ 'foo' ] },
  children: 
   [ { type: 'element',
       tagName: 'span',
       properties: {},
       children: [ { type: 'text', value: 'some text' } ] },
     { type: 'element',
       tagName: 'input',
       properties: { type: 'text', value: 'foo' },
       children: [] },
     { type: 'element',
       tagName: 'a',
       properties: { className: [ 'alpha', 'bravo', 'charlie' ], download: true },
       children: 
        [ { type: 'text', value: 'delta' },
          { type: 'text', value: 'echo' } ] } ] }

API

h(selector?[, properties][, children])

DSL for creating virtual HAST trees.

Parameters
  • selector (string, optional) — Simple CSS selector, e.g., tag names (foo), IDs (#bar) and classes (.baz) are supported, defaults to a div element.

  • properties (Object.<string, *>, optional) — Map of properties;

  • children (string, Node, Array.<string|Node>, optional) — (List of) child nodes, when strings are encountered, they are normalised to text nodes.

Returns

Node — A HAST node.

License

MIT © Titus Wormer