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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@purrtrait/client-tsx

v0.0.11

Published

In-browser TypeScript/TSX parsing and AST utilities.

Readme

@purrtrait/client-tsx

In-browser TypeScript/TSX parsing and AST utilities.

This package is part of the @purrtrait toolkit.

This package provides low-level utilities for parsing, inspecting, and serializing TypeScript and TSX code in the browser.

Although it focuses purely on language structure, not execution, rendering, or UI composition, it was designed for interactive component environments: documentation sandboxes, visual editors, and runtime JSX evaluation in the browser.

It is not a build tool replacement and should not be used for production compilation pipelines.

Features

  • Parse TS / TSX into TypeScript AST
  • Serialize AST nodes into string representations
  • Extract typed value models from JSX and TypeScript expressions

Installation

npm install @purrtrait/client-tsx

⚠️ Peer dependencies: Also install if not in your project already:

  • typescript

Usage

Parsing a simple TS expression

const input = `[1, 2, 3]`;
const ast = parseSource(input);

Output is approximatelly:

ts.SourceFile
└─ts.ArrayLiteralExpression
  ├─ ts.NumericLiteral
  ├─ ts.NumericLiteral
  └─ ts.NumericLiteral

Parsing TSX expressions

const input = `<Button>{foo}</Button>`;
const parsed = parseSource(input);

Output is approximatelly:

ts.Source.file
└─ts.JSXEpression
  ├─ ts.JsxOpeningElement (Button)
  ├─ ts.JsxExpression (foo)
  └─ ts.JsxClosingElement

Extracting props from JSX

const input = `<Button variant="danger"><Icon icon={TrashIcon}/> Delete</Button>`;
const sourceFile = parseSource(source.trim());
const props = extractProps(input, sourceFile);

Outputs a map of TSXNode for all props, including children.

{
  variant: {
    type: 'expression',
    tsNode: ts.StringLiteral,
    serialized: 'danger'
  },
  children: {
    type: 'JSX',
    tsNode: ts.JsxFragment,
    serialized: '<><Icon icon={TrashIcon}/> Delete</>'
  }
}

API

parseSource(source: string)

Parses TS/TSX source into a TypeScript AST.

function parseSource(source: string): ts.SourceFile;
printNode(node: ts.Node)

printNode(source: string)

Serializes a TypeScript AST node back into its source code.

Note that this does not execute any code or compile JSX.

function printNode(node: ts.Node): string;

extractProps(node: ts.Node)

Extracts JSX props, including children, from a JSX expression such as <Button variant="danger">....</Button> into lightweight TSXNode.

The optional ignore param can be used to filter out specific props.

export function extractProps(
  node: TypescriptComponentNode,
  sourceFile: ts.SourceFile,
  ignore?: (attr: ts.JsxAttribute) => boolean,
): Record<string, TSXNode>;

Node types

These types are used to classify types of TS nodes that are especially relevant for building documentation

type TSXElementNode = {
  type: 'jsx';
  tsNode: TypescriptElementNode;
  serialized: string;
};

type TSXHandlerNode = {
  type: 'handler';
  tsNode: TypescriptFunctionNode;
  serialized: string;
};

type TSXExpressionNode = {
  type: 'expression';
  tsNode: ts.Expression;
  serialized: string;
};

type TSXNode = TSXElementNode | TSXHandlerNode | TSXExpressionNode;

Development

Make sure you read the @purrtrait README first.

Build Targets

This library is distributed as ESM and intended to be processed by a bundler such as Vite or Astro. The main entry point is the Typescript source code.

Scripts

  • $ npm run dev - uses Vite to (re)build on changes
  • $ npm run build - uses Vite to do produce a dry build in dist/.
  • $ npm run lint / npm run lint:fix - uses @noodlestan/eslint-config.

MIT License

Copyright (c) 2026 Noodlestan.

Published under a MIT license.