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.
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!"
}
]
}
]
}
Run nx build cast-util-to-hast
to build the library.
Run nx test cast-util-to-hast
to execute the unit tests via Vitest.