@larsbaalmans/cast-util-to-hast
v1.2.0
Published
This library is part of the [CAST]() abstract syntax tree utilities. It provides a utility to convert a [CAST]() abstract syntax tree to a [Hast]() abstract syntax tree.
Downloads
71
Readme
cast-util-to-hast
This library is part of the CAST abstract syntax tree utilities. It provides a utility to convert a CAST abstract syntax tree to a Hast abstract syntax tree.
Usage
Using the utility cast
to hast
looks as follows:
/**
* @import {Root} from 'cast'
*/
import {toHast} from 'cast-util-to-hast'
/** @type {Root} */
const tree = {
type: 'root',
children: [
{
type: 'paragraph',
children: [
{ type: 'text', value: 'Hello, world!' }
]
}
]
}
console.info(toHast(tree))
yields:
{
"type": "root",
"children": [
{
"type": "element",
"tagName": "p",
"properties": {},
"children": [
{
"type": "text",
"value": "Hello, world!"
}
]
}
]
}
Building
Run nx build cast-util-to-hast
to build the library.
Running unit tests
Run nx test cast-util-to-hast
to execute the unit tests via Vitest.