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

jsx-jsonml-devtools-renderer

v1.4.3

Published

A JSX render for Chrome Devtools.

Downloads

12

Readme

jsx-jsonml-devtools-renderer npm

This is a Custom Object Formatter for rendering JSX objects in Chrome Devtools. Yes, you can see them in the console now!

How to use

import React from "jsx-jsonml-devtools-renderer";
class MyObject {
  type = 1;
  innerData = "innerData";
}
class MyObjectCustomFormatter implements React.CustomObjectFormatter {
  hasBody(obj: unknown) {
    if (obj instanceof MyObject) return true;
    return false;
  }
  body(obj: MyObject) {
    return (
      <div>
        <table>
          <tr style="background: rgba(255, 255, 255, 0.6)">
            <td style="min-width: 4em">Type</td>
            <td>Value</td>
          </tr>
          <tr>
            <td>{obj.type}</td>
            <td>{obj.innerData}</td>
          </tr>
        </table>
      </div>
    );
  }
  header(obj: unknown) {
    if (!(obj instanceof MyObject)) return null;
    return <div>MyObject (type: {obj.type})</div>;
  }
}
React.installCustomObjectFormatter(new MyObjectCustomFormatter());

Standard Custom Object Formatters features

| | div | span | ol | li | table | tr | td | object | | ------ | --- | ---- | --- | --- | ----- | --- | --- | ------ | | style | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ | | object | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✔ |

NON-Standard Custom Object Formatters features

  • an onClick attribute is available for any tags except object. Due to technical limitation, the onClick event will be only fired once.
  • an img tag. With attributes src(required), width(optional) and height(optional)
  • a code tag.
  • a br tag.
  • a variant attribute is available for any tags except object. It can used to specify some default styles.

APIs

  • Fragment (Used to support <></> syntax)
  • createElement (used to support JSX)
  • createElementTyped (same as createElement, but have a more stricter type)
  • installCustomObjectFormatter(formatter) (install the formatter to Chrome devtools)
  • isJSXElement(x) is it a JSX Element
  • const [state, setState, forceRender] = useState(inspectedObject, initialStateCreator) (used to preserve states between renders)

JSX Features

Basic usage

return (
    <div style="opacity: 0.7;">
        Content
        <span>(Note)</span>
    </div>
)

Display an object

return (
    <span>
        The explicit way: <object object={window} />
        The implicit way: {window}. If window is `null`, renderer will ignore this element.
    </span>
)

Array#map

return (
    <span>
        {data.map(x => (
            <object object={x} />
        ))}
    </span>
)