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

yuku-ast

v0.1.5

Published

A fast, typed AST toolkit for yuku-parser's ESTree / TypeScript-ESTree AST: node builders, type guards, and identifier validators.

Downloads

802

Readme

yuku-ast

A fast, fully typed AST toolkit for yuku-parser: node builders, type guards, and identifier validators.

| Import | Provides | | --------------------- | --------------------------------------- | | yuku-ast | b (node builders), is (type guards) | | yuku-ast/utils | node utilities such as nameOf | | yuku-ast/identifier | identifier and reserved-word validators |

import { parse } from "yuku-parser";
import { b, is } from "yuku-ast";

const { program } = parse("const greet = 1;");

const decl = program.body[0];
if (is.VariableDeclaration(decl)) {
  // `decl` is narrowed; swap the initializer for a freshly built node.
  decl.declarations[0].init = b.numericLiteral(42);
}

Install

bun add yuku-ast

Type guards (is)

A guard for every node type, the alias families, and the variants that share a type string. All accept null / undefined and return false.

import { is } from "yuku-ast";

is.CallExpression(node); // every concrete type
is.Expression(node); // families
is.StringLiteral(node); // Literal variants
is.StaticMemberExpression(node); // MemberExpression variants

is.Identifier(node, "this"); // an Identifier with that exact name
is.oneOf(node, ["CallExpression", "NewExpression"]); // any of these types

is.oneOf(node, types) narrows to the union of the listed types, and is.Identifier(node, name?) narrows to Identifier. A matching guard narrows the node for typed field access:

const element = arrayExpression.elements[0];
if (is.Identifier(element)) {
  element.name; // `element` is narrowed to Identifier
}

Aliases: Expression, Statement, Declaration, ModuleDeclaration, Function, Class, Method, Loop, Pattern, JSX, TSType.

Reading names (nameOf)

nameOf(node) returns the static name a node denotes, an Identifier's name or a string Literal's value, and null for anything else (including null or undefined). It reads the common Identifier | StringLiteral slots, such as a ModuleExportName or a static property or member key, in one call.

import { nameOf } from "yuku-ast/utils";

// `export { x as y }` and `export { x as "z" }` both resolve.
nameOf(specifier.exported); // "y", "z"

// A static (non-computed) property key, else null.
if (!property.computed) nameOf(property.key);

Builders (b)

A builder for every node type. Required fields are positional, the rest go in a trailing options object. Synthetic nodes get a zero span.

import { b } from "yuku-ast";

b.identifier("x");
b.callExpression(b.identifier("f"), [b.numericLiteral(1)]);
b.arrowFunctionExpression([b.identifier("a")], b.identifier("a"));
b.variableDeclaration("const", [b.variableDeclarator(b.identifier("x"), b.numericLiteral(0))]);

When you assign a synthetic node in place of an existing one, copy the original's start / end first so yuku-codegen source maps still point back to the original input.

Build and print

Pair it with yuku-codegen to print a built tree back to source.

import { print } from "yuku-codegen";
import { b } from "yuku-ast";

const program = b.program([
  b.variableDeclaration("const", [b.variableDeclarator(b.identifier("x"), b.numericLiteral(42))]),
  b.expressionStatement(
    b.callExpression(b.memberExpression(b.identifier("console"), b.identifier("log")), [
      b.identifier("x"),
    ]),
  ),
]);

console.log(print(program).code);
// const x = 42;
// console.log(x);

Identifiers

Identifier and reserved-word helpers for raw strings and code points.

import { isIdentifierName, isValidIdentifier } from "yuku-ast/identifier";

isIdentifierName("π"); // true  - a well-formed IdentifierName
isIdentifierName("class"); // true  - purely syntactic, keywords included
isValidIdentifier("class"); // false - rejects reserved words (use for bindings)
isValidIdentifier("π"); // true

| Function | Checks | | ------------------------------------------------ | ------------------------------------------------------------------------- | | isIdentifierName(name) | name is a syntactically valid IdentifierName | | isValidIdentifier(name, reserved?) | a valid binding name; rejects reserved words unless reserved is false | | isIdentifierStart(cp) / isIdentifierChar(cp) | a code point may start / continue an identifier | | isKeyword(word) | word is a core grammar keyword (if, class, …) | | isReservedWord(word, inModule?) | reserved everywhere (enum; await in modules) | | isStrictReservedWord(word, inModule?) | also reserved in strict mode (let, yield, …) | | isStrictBindOnlyReservedWord(word) | eval / arguments | | isStrictBindReservedWord(word, inModule?) | strict reserved, plus eval / arguments |

License

MIT