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

react-delver

v0.1.12

Published

`react-delver` is a design system analysis tool and provides a Node API to analyze your app's JSX. Here's a [demo of a UI](https://react-delver-ui.vercel.app/) built around this API using the [react-delver-ui](https://github.com/jonambas/react-delver-ui)

Downloads

19

Readme

react-delver

react-delver is a design system analysis tool and provides a Node API to analyze your app's JSX. Here's a demo of a UI built around this API using the react-delver-ui package.

react-delver will turn:

function App() {
  return (
    <Foo bar="baz">
      <Bar foo />
    </Foo>
  );
}

into this:

[
  {
    "name": "Bar",
    "count": 1,
    "from": "src/file.js",
    "instances": [
      {
        "name": "Bar",
        "spread": false,
        "props": [{ "value": true, "name": "foo" }],
        "location": {
          "file": "src/file.js",
          "line": 8,
          "character": 6
        }
      }
    ]
  },
  {
    "name": "Foo",
    "count": 1,
    "from": "src/file.js",
    "instances": [
      {
        "name": "Foo",
        "spread": false,
        "props": [{ "value": "baz", "name": "bar" }],
        "location": {
          "file": "src/file.js",
          "line": 7,
          "character": 6
        }
      }
    ]
  }
]

Node API

npm i react-delver --save-dev
const { delve } = require('react-delver');

const results = delve({ include: 'src/**/*.{jsx,tsx,js,ts}' });
type Props = Array<{
  value: string | boolean | number | null | undefined;
  name: string;
  expression: boolean;
}>;

type Instance = {
  name: string;
  spread: boolean;
  props: Props;
  from: string | undefined;
  location: {
    file: string;
    line: number;
    character: number;
  };
};

type Result = {
  name: string;
  count: number;
  from: 'indeterminate' | string | undefined;
  instances: Array<Instance>;
};

type Results = Array<Result>;

options.include

Type: string | string[]

Array of globs patterns for your React code to parse. See fast-glob for more information.

The node API does not exlude any directories by default, so you may want to specify commonly ignored directories, like '!**/node_modules' or '!**/dist'.

options.ignoreSubComponents

Type: boolean

Default: false

Whether to include subcomponents or not. For example, when set to true, <Foo.Bar /> will be ignored.

options.raw

Type: boolean

Default: false

Whether to aggregate the results or not. When set to true, data will be a flat array of all component instances.

When set to false, data will be grouped by component name and include count and from. count is the total number of component instances. from will be either:

  • string - all component instances were imported from the same package
  • 'indeterminate' - component instances do not share the same import path or package
  • undefined - all component instances were not imported at all

options.from

Type: string[]

If included, only include components that are imported from this list of packages. For example, if you only want to include components imported from @src/components, use from: ['@src/components'].

options.expressionLength

Type: number

Default: 40

Truncates JS expressions detected in props to this length.


Limitations

react-delver uses typescript's compiler API to parse through your JSX.

  • Components will only be detected when explicitly rendered with JSX, ie <MyComponent />.
  • Components may not accurately represent their displayName if they are aliased or renamed.
  • Prop values that contain expressions such as variables or functions are not evaluated, but are stringified and truncated.

License

MIT