unified

Project: syntax-tree/unist-builder

Package: unist-builder@2.0.3

  1. Dependencies: 0·Dependents: 116
  2. unist utility to create a new trees with a nice syntax
  1. util 107
  2. utility 105
  3. unist 97
  4. tree 40
  5. syntax 30
  6. ast 27
  7. unist-util 24
  8. dsl 5
  9. hyperscript 5
  10. create 2

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

Use

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
Parameters
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, organization, or community you agree to abide by its terms.

License

MIT © Eugene Sharygin