unist-builder
unist utility to create a new trees with a nice syntax
Last updated a month ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install unist-builder 
SYNC missed versions from official npm registry.

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
  • 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.

Related

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

Current Tags

  • 2.0.3                                ...           latest (a month ago)

9 Versions

  • 2.0.3                                ...           a month ago
  • 2.0.2                                ...           5 months ago
  • 2.0.1                                ...           5 months ago
  • 2.0.0                                ...           5 months ago
  • 1.0.4                                ...           10 months ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 215
This Week 3,352
This Month 10,437
Last Day 259
Last Week 2,579
Last Month 4,923
Dependencies (0)
None
Dev Dependencies (8)
Dependents (146)

Copyright 2014 - 2016 © taobao.org |