unified

Project: syntax-tree/unist-builder-blueprint

Package: unist-builder-blueprint@1.1.1

  1. Dependencies: 0·Dependents: 2
  2. unist utility to transform trees to unist-builder notation
  1. util 107
  2. utility 105
  3. unist 97
  4. tree 37
  5. syntax 27
  6. unist-util 24
  7. ast 24
  8. cst 8
  9. unist-builder 2
  10. blueprint 2

unist-builder-blueprint

Build Coverage Downloads Sponsors Backers Chat

unist utility to transform trees to unist-builder notation.

Install

npm:

npm install unist-builder-blueprint

Use

var escodegen = require('escodegen')
var toU = require('unist-builder-blueprint')

var 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}
      ]
    }
  ]
}

var estree = toU(tree)

console.log(escodegen.generate(estree, {format: {indent: {style: '  '}}}))

Yields:

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 })
  ])
])

API

toU(tree[, options])

Transform the given tree to unist-builder notation.

Parameters
Returns

ESTreeCallExpression.

To generate actual JavaScript code from the result, use one of the existing code generators, such as escodegen.

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