8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- [ ** unist** ] [ unist ] utility to create a new [ tree] [ ] s with [ hyperscript] [ ] -like
12
- syntax.
11
+ [ unist] [ ] utility to create trees with ease.
13
12
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.
15
31
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
18
43
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] [ ] :
20
46
21
- ``` bash
47
+ ``` sh
22
48
npm install unist-builder
23
49
```
24
50
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
+
25
65
## Use
26
66
27
67
``` js
28
68
import {u } from ' unist-builder'
29
69
30
- var tree = u (' root' , [
70
+ const tree = u (' root' , [
31
71
u (' subtree' , {id: 1 }),
32
72
u (' subtree' , {id: 2 }, [
33
73
u (' node' , [u (' leaf' , ' leaf 1' ), u (' leaf' , ' leaf 2' )]),
@@ -67,7 +107,7 @@ results in the following tree:
67
107
68
108
## API
69
109
70
- This package exports the following identifiers: ` u ` .
110
+ This package exports the identifier ` u ` .
71
111
There is no default export.
72
112
73
113
### ` u(type[, props][, children|value]) `
@@ -76,14 +116,14 @@ Creates a node from `props`, `children`, and optionally `value`.
76
116
77
117
###### Signatures
78
118
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)
82
122
83
123
###### Parameters
84
124
85
125
* ` type ` (` string ` )
86
- — node [ type] [ ]
126
+ — node type
87
127
* ` props ` (` Record<string, unknown> ` )
88
128
— other values assigned to ` node `
89
129
* ` children ` ([ ` Array<Node> ` ] [ node ] )
@@ -95,19 +135,29 @@ Creates a node from `props`, `children`, and optionally `value`.
95
135
96
136
[ ` Node ` ] [ node ] .
97
137
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
+
98
150
## Related
99
151
100
- * [ ` unist-builder-blueprint ` ] ( https://github.com/syntax-tree/unist-builder-blueprint )
101
- — Convert unist trees to ` unist-builder ` notation
102
152
* [ ` hastscript ` ] ( https://github.com/syntax-tree/hastscript )
103
- — Create [ hast] [ ] elements
153
+ — create [ hast] [ ] trees
104
154
* [ ` xastscript ` ] ( https://github.com/syntax-tree/xastscript )
105
- — Create [ xast] [ ] elements
155
+ — create [ xast] [ ] trees
106
156
107
157
## Contribute
108
158
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.
111
161
See [ ` support.md ` ] [ support ] for ways to get help.
112
162
113
163
This project has a [ code of conduct] [ coc ] .
@@ -148,28 +198,34 @@ abide by its terms.
148
198
149
199
[ npm ] : https://docs.npmjs.com/cli/install
150
200
151
- [ license ] : license
201
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
152
202
153
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
203
+ [ esmsh ] : https://esm.sh
154
204
155
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support.md
205
+ [ typescript ] : https://www.typescriptlang.org
156
206
157
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
207
+ [ license ] : license
158
208
159
- [ unist ] : https://github.com/syntax-tree/unist
209
+ [ health ] : https://github.com/syntax-tree/.github
160
210
161
- [ hast ] : https://github.com/syntax-tree/hast
211
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing.md
162
212
163
- [ xast ] : https://github.com/syntax-tree/xast
213
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support.md
164
214
165
- [ hyperscript ] : https://github.com/dominictarr/hyperscript
215
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
166
216
167
- [ node ] : https://github.com/syntax-tree/unist#node
217
+ [ unist ] : https://github.com/syntax-tree/unist
168
218
169
- [ tree ] : https://github.com/syntax-tree/unist#tree
219
+ [ node ] : https://github.com/syntax-tree/unist#node
170
220
171
221
[ parent ] : https://github.com/syntax-tree/unist#parent
172
222
173
223
[ literal ] : https://github.com/syntax-tree/unist#literal
174
224
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