Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3
utility to create a new trees with a nice syntax
License
syntax-tree/unist-builder
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
unist utility to create trees with ease.
This package is a hyperscript interface (likecreateElement from React andh from Vue and such) to help with creating unist trees.
You can use this utility in your project when you generate syntax trees withcode.It helps because it replaces most of the repetition otherwise needed in a syntaxtree with function calls.
You can instead usehastscript orxastscriptwhen creating hast (HTML) or xast (XML) nodes.
This package isESM only.In Node.js (version 16+), install withnpm:
npm install unist-builder
In Deno withesm.sh:
import{u}from'https://esm.sh/unist-builder@4'
In browsers withesm.sh:
<scripttype="module">import{u}from'https://esm.sh/unist-builder@4?bundle'</script>
import{u}from'unist-builder'consttree=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:undefined})
…yields:
{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}]}]}
This package exports the identifieru.There is no default export.
Build a node.
u(type[, props], children)— create a parent (Parent)u(type[, props], value)— create a literal (Literal)u(type[, props])— create a void node (neither parent not literal)
type(string)— node typeprops(Record<string, unknown>)— fields assigned to nodechildren(Array<Node>)— children of nodevalue(*)— value ofnode(cast to string)
Built node (Node).
List to use aschildren or value to use asvalue (TypeScript type).
typeChildrenOrValue=Array<Node>|string
Other fields to add to the node (TypeScript type).
exporttypeProps=Record<string,unknown>
This package is fully typed withTypeScript.It exports the additional typesChildrenOrValue andProps.
Projects maintained by the unified collective are compatible with maintainedversions of Node.js.
When we cut a new major release, we drop support for unmaintained versions ofNode.This means we try to keep the current release line,unist-builder@^4,compatible with Node.js 16.
hastscript— createhast treesxastscript— createxast trees
Seecontributing.md insyntax-tree/.github forways to get started.Seesupport.md for ways to get help.
This project has acode of conduct.By interacting with this repository, organization, or community you agree toabide by its terms.
MIT © Eugene Sharygin
About
utility to create a new trees with a nice syntax
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.