JSPM

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

Helper for creating unist trees

Package Exports

  • unist-builder

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 (unist-builder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

unist-builder

Build Coverage Downloads Size Sponsors Backers Chat

unist utility to create a new trees with hyperscript-like syntax.

Install

npm:

npm install unist-builder

Usage

var u = require('unist-builder')

var tree = u('root', [
  u('subtree', {id: 1}),
  u('subtree', {id: 2}, [
    u('node', [u('leaf', 'leaf 1'), u('leaf', 'leaf 2')]),
    u('leaf', {id: 3}, 'leaf 3'),
    u('void', {id: 4})
  ])
])

console.dir(tree, {depth: null})

results in the following tree:

{
  type: 'root',
  children: [
    {type: 'subtree', id: 1},
    {
      type: 'subtree',
      id: 2,
      children: [
        {
          type: 'node',
          children: [
            {type: 'leaf', value: 'leaf 1'},
            {type: 'leaf', value: 'leaf 2'}
          ]
        },
        {type: 'leaf', id: 3, value: 'leaf 3'},
        {type: 'void', id: 4}
      ]
    }
  ]
}

API

u(type[, props][, children|value])

Creates a node from props, children, and optionally value.

Signatures
  • u(type[, props], children) — create a parent
  • u(type[, props], value) — create a literal
  • u(type[, props]) — create a void node
Parameters
  • type (string) — node type
  • props (Object) — other values assigned to node
  • children (Array.<Node>) — children of node
  • value (*) — value of node (cast to string)
Returns

Node.

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Eugene Sharygin