esast utility to build trees
This is a tiny but useful utility for building esast nodes.
Use this package when you need to create esast nodes.
If you need to build nodes for other ASTs, use unist-util-builder
instead.
This package is ESM only.
In Node.js (version 18+) with yarn:
yarn add @flex-development/esast-util-builder
See Git - Protocols | Yarn for details regarding installing from Git.
In Deno with esm.sh
:
import { u } from 'https://esm.sh/@flex-development/esast-util-builder'
In browsers with esm.sh
:
<script type="module">
import { u } from 'https://esm.sh/@flex-development/esast-util-builder'
</script>
TODO: use
This package exports the identifier u
. There is no default export.
Build an esast node using a child node array, properties object, or value.
If builder
is omitted, a void node (a node with only a type
field) will be created.
👉 Undefined literals must be created using a properties object, rather than a value. Passing
undefined
will create a void node.
T
(Type<AnyNode>
) - esast node type
type
(T
) - esast node typebuilder
(Builder<T>
, optional) - node children, properties, or value
Match<AnyNode, T>
new esast node.
Union of nodes that can occur in esast (TypeScript type).
👉 This type is exported from
@flex-development/esast
.
SeeAnyNode
for more details.
Construct a union of esast node builders (TypeScript type).
See also: ub.AnyBuilder
, ub.Builder
type Builder<T extends Type = Type<AnyNode>> = T extends Type<AnyNode>
? ub.Builder<Match<AnyNode, T>> extends infer B extends ub.AnyBuilder
? B extends ub.BuilderValue
? B
: B extends readonly Node[]
? B[number][]
: {
[K in keyof B]: K extends 'children'
? B[K] extends infer U extends readonly Node[]
? U[number][]
: never
: B[K]
}
: never
: never
Check if node N
passes a test. (TypeScript type).
👉 This type is exported from
@flex-development/unist-util-types
.
SeeMatch<N, Check>
for more details.
Extract type from node T
(TypeScript type).
👉 This type is exported from
@flex-development/unist-util-types
.
SeeType<[T]>
for more details.
This package is fully typed with TypeScript.
esast
— ecmascript abstract syntax tree format
See CONTRIBUTING.md
.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.