@@ -23,8 +23,20 @@ It implements the [**unist**][unist] spec.
2323 - [ Where this specification fits] ( #where-this-specification-fits )
2424- [ Types] ( #types )
2525- [ Nodes (abstract)] ( #nodes-abstract )
26+ - [ ` Node ` ] ( #node )
27+ - [ ` Literal ` ] ( #literal )
28+ - [ ` Parent ` ] ( #parent )
2629- [ Nodes] ( #nodes )
30+ - [ ` Directory ` ] ( #directory )
31+ - [ ` File ` ] ( #file )
32+ - [ ` Root ` ] ( #root )
2733- [ Content model] ( #content-model )
34+ - [ ` DirectoryContent ` ] ( #directorycontent )
35+ - [ ` FstNode ` ] ( #fstnode )
36+ - [ Helpers] ( #helpers )
37+ - [ ` AnyNode ` ] ( #anynode )
38+ - [ ` AnyParent ` ] ( #anyparent )
39+ - [ ` Child ` ] ( #child )
2840- [ Glossary] ( #glossary )
2941- [ List of utilities] ( #list-of-utilities )
3042- [ Contribute] ( #contribute )
@@ -48,15 +60,150 @@ yarn add @flex-development/fst
4860
4961## Nodes (abstract)
5062
51- ** TODO** : nodes (abstract)
63+ ### ` Node `
64+
65+ ``` ts
66+ interface Node extends unist .Node {}
67+ ```
68+
69+ ** Node** ([ ** unist.Node** ] [ unist-node ] ) is a syntactic unit in fst syntax trees.
70+
71+ ### ` Literal `
72+
73+ ``` ts
74+ interface Literal extends Node {
75+ value: string | null | undefined
76+ }
77+ ```
78+
79+ ** Literal** represents an abstract interface in fst containing the smallest possible value.
80+
81+ ### ` Parent `
82+
83+ ``` ts
84+ interface Parent extends unist .Parent {
85+ children: Child []
86+ }
87+ ```
88+
89+ ** Parent** ([ ** unist.Parent** ] [ unist-parent ] ) represents an abstract interface in fst containing other nodes (said to
90+ be [ * children* ] [ unist-child ] ).
91+
92+ Its content is limited to [ file system content] ( #child ) .
5293
5394## Nodes
5495
55- ** TODO** : nodes
96+ ### ` Directory `
97+
98+ ``` ts
99+ interface Directory extends Parent {
100+ children: DirectoryContent []
101+ data? : DirectoryData | undefined
102+ name: string
103+ type: ' directory'
104+ }
105+ ```
106+
107+ ** Directory** ([ ** Parent** ] ( #parent ) ) represents a parent directory or subdirectory. Its ` name ` is relative to its
108+ parent directory.
109+
110+ ** Directory** can be used in [ ** root** ] ( #root ) nodes, as well as other ** directory** nodes. Its content model is
111+ [ ** directory** ] ( #directorycontent ) .
112+
113+ ### ` File `
114+
115+ ``` ts
116+ interface File extends Literal {
117+ data? : FileData | undefined
118+ name: string
119+ type: ' file'
120+ value: string | null | undefined
121+ }
122+ ```
123+
124+ ** File** ([ ** Literal** ] ( #literal ) ) represents a file.
125+
126+ File ` name ` s are relative to the parent directory. Unlike the name property of a [ ` ParsedPath ` ] [ parsedpath ] , file ` name ` s
127+ include file extensions.
128+
129+ ** File** can be used in [ ** directory** ] ( #directory ) and [ ** root** ] ( #root ) nodes. It cannot contain any children — it is
130+ a [ * leaf* ] [ unist-leaf ] .
131+
132+ ### ` Root `
133+
134+ ``` ts
135+ interface Root extends Parent {
136+ children: DirectoryContent []
137+ data? : RootData | undefined
138+ path: string
139+ type: ' root'
140+ }
141+ ```
142+
143+ ** Root** ([ ** Parent** ] ( #parent ) ) represents the root of a file system.
144+
145+ ** Root** can be used as the [ * root* ] [ unist-root ] of a [ * tree* ] [ unist-tree ] , never as a [ * child* ] [ unist-child ] . It can
146+ contain [ ** directory content** ] ( #directorycontent ) .
56147
57148## Content model
58149
59- ** TODO** : content model
150+ ### ` DirectoryContent `
151+
152+ ``` ts
153+ type DirectoryContent = Directory | File
154+ ` ` `
155+
156+ **Directory** content represents files and subdirectories in a parent [**directory**](#directory).
157+
158+ ### ` FstNode `
159+
160+ ` ` ` ts
161+ type FstNode = NodeMap [keyof NodeMap ]
162+ ` ` `
163+
164+ Registered fst nodes.
165+
166+ To register custom nodes, augment ` NodeMap ` :
167+
168+ ` ` ` ts
169+ declare module ' @flex-development/fst' {
170+ interface NodeMap {
171+ customNode: CustomNode
172+ }
173+ }
174+ ```
175+
176+ ## Helpers
177+
178+ ### ` AnyNode `
179+
180+ Union of nodes that can occur in fst.
181+
182+ ** See also** : [ ` InclusiveDescendant ` ] [ inclusivedescendant ]
183+
184+ ``` ts
185+ type AnyNode = InclusiveDescendant <Root >
186+ ` ` `
187+
188+ ### ` AnyParent `
189+
190+ Union of [*parents*][unist-parent] that are [*inclusive descendants*][descendant] of [ ` Root ` ](#root).
191+
192+ **See also**: [ ` Parents ` ][parents]
193+
194+ ` ` ` ts
195+ type AnyParent = Parents <Root >
196+ ` ` `
197+
198+ ### ` Child `
199+
200+ Union of [*child*][unist-child] nodes that can occur in fst.
201+
202+ **See also**: [ ` Children ` ][children]
203+
204+ ` ` ` ts
205+ type Child = Children <AnyParent >[number ]
206+ ` ` `
60207
61208## Glossary
62209
@@ -80,33 +227,41 @@ Ideas for new utilities and tools can be posted in [fst/ideas][fst-ideas].
80227This project has a [code of conduct](CODE_OF_CONDUCT.md). By interacting with this repository, organization, or
81228community you agree to abide by its terms.
82229
230+ [children]: https://github.com/flex-development/unist-util-types#childrent
231+
232+ [descendant]: https://github.com/syntax-tree/unist#descendant
233+
83234[fst-ideas]: https://github.com/flex-development/fst/discussions/new?category=idea
84235
85236[fst-util-from-fs]: https://github.com/flex-development/fst-util-from-fs
86237
238+ [inclusivedescendant]: https://github.com/flex-development/unist-util-types#inclusivedescendanttree-max-depth
239+
240+ [parents]: https://github.com/flex-development/unist-util-types#parentstree-child
241+
242+ [parsedpath]: https://github.com/flex-development/pathe/blob/main/src/interfaces/parsed-path.mts
243+
87244[postorder]: https://github.com/syntax-tree/unist#postorder
88245
89246[preorder]: https://github.com/syntax-tree/unist#preorder
90247
91248[typescript]: https://www.typescriptlang.org
92249
93- <!-- [unist-child]: https://github.com/syntax-tree/unist#child -->
94-
95- <!-- [unist-file]: https://github.com/syntax-tree/unist#file -->
250+ [unist-child]: https://github.com/syntax-tree/unist#child
96251
97252[unist-glossary]: https://github.com/syntax-tree/unist#glossary
98253
99- <!-- [unist-leaf]: https://github.com/syntax-tree/unist#leaf -->
254+ [unist-leaf]: https://github.com/syntax-tree/unist#leaf
100255
101- <!-- [unist-node]: https://github.com/syntax-tree/unist#node -->
256+ [unist-node]: https://github.com/syntax-tree/unist#node
102257
103- <!-- [unist-parent]: https://github.com/syntax-tree/unist#parent -->
258+ [unist-parent]: https://github.com/syntax-tree/unist#parent
104259
105- <!-- [unist-root]: https://github.com/syntax-tree/unist#root -->
260+ [unist-root]: https://github.com/syntax-tree/unist#root
106261
107262[unist-syntax-tree]: https://github.com/syntax-tree/unist#syntax-tree
108263
109- <!-- [unist-tree]: https://github.com/syntax-tree/unist#tree -->
264+ [unist-tree]: https://github.com/syntax-tree/unist#tree
110265
111266[unist-util-builder]: https://github.com/flex-development/unist-util-builder
112267
0 commit comments