@larsbaalmans/cast-util-to-hast
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @larsbaalmans/cast-util-to-hast

Weekly Downloads

0

Version

1.2.0

License

none

Unpacked Size

6.2 kB

Total Files

6

Last publish

Collaborators

  • larsbaalmans