88[ ![ Backers] [ backers-badge ]] [ collective ]
99[ ![ Chat] [ chat-badge ]] [ chat ]
1010
11- [ ** unist** ] [ unist ] utility to create a new [ tree] [ ] s with [ hyperscript] [ ] -like
12- syntax.
11+ [ unist] [ ] utility to create trees with ease.
1312
14- ## Install
13+ ## Contents
14+
15+ * [ What is this?] ( #what-is-this )
16+ * [ When should I use this?] ( #when-should-i-use-this )
17+ * [ Install] ( #install )
18+ * [ Use] ( #use )
19+ * [ API] ( #api )
20+ * [ ` u(type[, props][, children|value]) ` ] ( #utype-props-childrenvalue )
21+ * [ Types] ( #types )
22+ * [ Compatibility] ( #compatibility )
23+ * [ Related] ( #related )
24+ * [ Contribute] ( #contribute )
25+ * [ License] ( #license )
26+
27+ ## What is this?
28+
29+ This package is a hyperscript interface (like ` createElement ` from React and
30+ ` h ` from Vue and such) to help with creating unist trees.
1531
16- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
17- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
32+ ## When should I use this?
33+
34+ You can use this utility in your project when you generate syntax trees with
35+ code.
36+ It helps because it replaces most of the repetition otherwise needed in a syntax
37+ tree with function calls.
38+
39+ You can instead use [ ` hastscript ` ] [ hastscript ] or [ ` xastscript ` ] [ xastscript ]
40+ when creating hast (HTML) or xast (XML) nodes.
41+
42+ ## Install
1843
19- [ npm] [ ] :
44+ This package is [ ESM only] [ esm ] .
45+ In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [ npm] [ ] :
2046
21- ``` bash
47+ ``` sh
2248npm install unist-builder
2349```
2450
51+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
52+
53+ ``` js
54+ import {h } from ' https://esm.sh/unist-builder@3'
55+ ```
56+
57+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
58+
59+ ``` html
60+ <script type =" module" >
61+ import {h } from ' https://esm.sh/unist-builder@3?bundle'
62+ </script >
63+ ```
64+
2565## Use
2666
2767``` js
2868import {u } from ' unist-builder'
2969
30- var tree = u (' root' , [
70+ const tree = u (' root' , [
3171 u (' subtree' , {id: 1 }),
3272 u (' subtree' , {id: 2 }, [
3373 u (' node' , [u (' leaf' , ' leaf 1' ), u (' leaf' , ' leaf 2' )]),
@@ -67,7 +107,7 @@ results in the following tree:
67107
68108## API
69109
70- This package exports the following identifiers: ` u ` .
110+ This package exports the identifier ` u ` .
71111There is no default export.
72112
73113### ` u(type[, props][, children|value]) `
@@ -76,14 +116,14 @@ Creates a node from `props`, `children`, and optionally `value`.
76116
77117###### Signatures
78118
79- * ` u(type[, props], children) ` — create a [ parent] [ ]
80- * ` u(type[, props], value) ` — create a [ literal] [ ]
81- * ` u(type[, props]) ` — create a void node
119+ * ` u(type[, props], children) ` — create a parent ( [ ` Parent ` ] [ parent ] )
120+ * ` u(type[, props], value) ` — create a literal ( [ ` Literal ` ] [ literal ] )
121+ * ` u(type[, props]) ` — create a void node (neither parent not literal)
82122
83123###### Parameters
84124
85125* ` type ` (` string ` )
86- — node [ type] [ ]
126+ — node type
87127* ` props ` (` Record<string, unknown> ` )
88128 — other values assigned to ` node `
89129* ` children ` ([ ` Array<Node> ` ] [ node ] )
@@ -95,19 +135,29 @@ Creates a node from `props`, `children`, and optionally `value`.
95135
96136[ ` Node ` ] [ node ] .
97137
138+ ## Types
139+
140+ This package is fully typed with [ TypeScript] [ ] .
141+ It exports the additional types ` Props ` and ` ChildrenOrValue ` .
142+
143+ ## Compatibility
144+
145+ Projects maintained by the unified collective are compatible with all maintained
146+ versions of Node.js.
147+ As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
148+ Our projects sometimes work with older versions, but this is not guaranteed.
149+
98150## Related
99151
100- * [ ` unist-builder-blueprint ` ] ( https://github.com/syntax-tree/unist-builder-blueprint )
101- — Convert unist trees to ` unist-builder ` notation
102152* [ ` hastscript ` ] ( https://github.com/syntax-tree/hastscript )
103- — Create [ hast] [ ] elements
153+ — create [ hast] [ ] trees
104154* [ ` xastscript ` ] ( https://github.com/syntax-tree/xastscript )
105- — Create [ xast] [ ] elements
155+ — create [ xast] [ ] trees
106156
107157## Contribute
108158
109- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
110- started.
159+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
160+ ways to get started.
111161See [ ` support.md ` ] [ support ] for ways to get help.
112162
113163This project has a [ code of conduct] [ coc ] .
@@ -148,28 +198,34 @@ abide by its terms.
148198
149199[ npm ] : https://docs.npmjs.com/cli/install
150200
151- [ license ] : license
201+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
152202
153- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
203+ [ esmsh ] : https://esm.sh
154204
155- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support.md
205+ [ typescript ] : https://www.typescriptlang.org
156206
157- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
207+ [ license ] : license
158208
159- [ unist ] : https://github.com/syntax-tree/unist
209+ [ health ] : https://github.com/syntax-tree/.github
160210
161- [ hast ] : https://github.com/syntax-tree/hast
211+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing.md
162212
163- [ xast ] : https://github.com/syntax-tree/xast
213+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support.md
164214
165- [ hyperscript ] : https://github.com/dominictarr/hyperscript
215+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
166216
167- [ node ] : https://github.com/syntax-tree/unist#node
217+ [ unist ] : https://github.com/syntax-tree/unist
168218
169- [ tree ] : https://github.com/syntax-tree/unist#tree
219+ [ node ] : https://github.com/syntax-tree/unist#node
170220
171221[ parent ] : https://github.com/syntax-tree/unist#parent
172222
173223[ literal ] : https://github.com/syntax-tree/unist#literal
174224
175- [ type ] : https://github.com/syntax-tree/unist#type
225+ [ hast ] : https://github.com/syntax-tree/hast
226+
227+ [ xast ] : https://github.com/syntax-tree/xast
228+
229+ [ hastscript ] : https://github.com/syntax-tree/hastscript
230+
231+ [ xastscript ] : https://github.com/syntax-tree/xastscript
0 commit comments