npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@liltrendi/reastify

v0.1.6

Published

Recursive module that converts html abstract syntax trees (AST's) into a renderable React element.

Downloads

12

Readme

Reastify

Recursive module that converts html abstract syntax trees (AST's) into a renderable React element.

This data follows the premise that it has one source of truth that branches into embedded (similar) children whose nodes are not known at compile time.

The AST that needs to be passed has a format similar to the one below:

let htmlAst = {
    type: "root",
    tagName: "p",
    properties: {},
    children: [
        {
            type: "text",
            value: "hello world"
        },
        {
            type: "element",
            tagName: "p",
            properties: {},
            children: [
                {
                    type: "element",
                    tagName: "a",
                    properties: {
                        href: "https://example.com/"
                    },
                    children: [
                        {
                            type: "text",
                            value: "www.example.com"
                        }
                    ]
                },
                {
                    type: "element",
                    tagName: "table",
                    properties: {},
                    children: [
                        {
                            type: "element",
                            tagName: "thead",
                            properties: {},
                            children: [
                                //it goes on and on and on
                            ]
                        }
                    ]
                },
                {
                    type: "text",
                    value: "random sample"
                },
            ]
        }
    ],
}

Installation

You can use Yarn:

yarn add @liltrendi/reastify

Or npm:

npm i @liltrendi/reastify

Usage

Import it into your app

import {reastify} from "@liltrendi/reastify"

And pretty much pass the AST data to the reastify function like so:

import React from "react"
import {reastify} from "@liltrendi/reastify"

const App = ({htmlAst}) => {
    let yourElement = reastify(htmlAst)
    return (
        <React.Fragment>
            {yourElement}
        </React.Fragment>
    )
}

export default App;

Props

The function uses a model based off of these typescript interfaces:

interface I_ReastifyNode {
    type?: string;
    tagName?: string;
    children?: any[];
    properties?: any;
    value?: any;
}

interface I_ReastifyProps {
    htmlAst?: I_ReastifyNode;
    tableClassName?: string;
    theadClassName?: string;
    tbodyClassName?: string;
    trClassName?: string;
    tdClassName?: string;
    thClassName?: string;
    pClassName?: string;
    h1ClassName?: string;
    h2ClassName?: string;
    h3ClassName?: string;
    h4ClassName?: string;
    h5ClassName?: string;
    h6ClassName?: string;
    imgClassName?: string;
    brClassName?: string;
    aClassName?: string;
    uClassName?: string;
    strongClassName?: string;
    emClassName?: string;
    ulClassName?: string;
    olClassName?: string;
    liClassName?: string;
    preClassName?: string;
    codeClassName?: string;
    linkOnclick?: (event: React.MouseEvent<HTMLElement>) => any;
}

To Do

Abstract it into a class with helper methods. PRs are welcome.