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

@aliou/sh

v0.1.0

Published

Shell parser/AST for POSIX/Bash/mksh/zsh (WIP)

Readme

@aliou/sh

TypeScript shell parser inspired by mvdan/sh. Parses POSIX/Bash shell commands into a typed AST.

Zero dependencies. Single exported function. ~28 KB bundled.

Usage

import { parse } from "@aliou/sh";

const { ast } = parse('echo "hello $USER" | grep hello');
// ast.type === "Program"
// ast.body[0].command.type === "Pipeline"

The parser returns a Program node containing Statement nodes. Each statement wraps a Command, which is one of:

  • SimpleCommand -- words, assignments, redirects
  • Pipeline, Logical (&&, ||)
  • IfClause, WhileClause, ForClause, SelectClause, CaseClause
  • FunctionDecl, Subshell, Block
  • TestClause ([[ ]]), ArithCmd ((( ))), CoprocClause, TimeClause
  • DeclClause (declare, local, export, readonly, typeset, nameref)
  • LetClause (let), CStyleLoop (for (( ; ; )))

Words contain typed parts: Literal, SglQuoted, DblQuoted, ParamExp, CmdSubst, ArithExp, ProcSubst.

Example: extract command names

import { parse, type SimpleCommand } from "@aliou/sh";

function extractCommandNames(node: unknown): string[] {
  if (!node || typeof node !== "object") return [];
  const n = node as Record<string, unknown>;
  const names: string[] = [];

  if (n.type === "SimpleCommand") {
    const cmd = n as unknown as SimpleCommand;
    if (cmd.words?.length) {
      const first = cmd.words[0];
      if (first.parts.length === 1 && first.parts[0].type === "Literal") {
        names.push(first.parts[0].value);
      }
    }
  }

  for (const val of Object.values(n)) {
    if (Array.isArray(val)) {
      for (const item of val) names.push(...extractCommandNames(item));
    } else if (val && typeof val === "object") {
      names.push(...extractCommandNames(val));
    }
  }
  return names;
}

const { ast } = parse("grep -rn npm package.json | head -5");
extractCommandNames(ast); // ["grep", "head"]

Supported syntax

  • Simple commands, pipelines, logical operators (&&, ||)
  • Single and double quotes, parameter expansion ($var, ${var:-default})
  • Command substitution ($(cmd), `cmd`), arithmetic expansion ($((expr)))
  • Process substitution (<(cmd), >(cmd))
  • Heredocs (<<, <<-), herestrings (<<<)
  • All redirect operators (>, >>, <, >&, <&, <>, >|, &>, &>>)
  • Assignments (FOO=bar cmd), append assignments (FOO+=bar)
  • Array expressions (arr=(a b c), arr=([0]=x [1]=y))
  • Declaration builtins as special forms (declare, local, export, readonly, typeset, nameref)
  • let expressions (let i++ j=2)
  • Control flow: if/elif/else/fi, while/until, for/in, for ((...)), select/in, case/esac
  • Functions (foo() {}, function foo {})
  • Subshells (), blocks {}
  • [[ ]] test expressions, (( )) arithmetic commands
  • coproc, time, negation (!)
  • Comments (optionally preserved via keepComments option), backslash line continuations, background (&), semicolons

Install

pnpm add github:aliou/sh

Development

Requires Nix (provides Node 22 and pnpm):

nix develop

pnpm install     # install deps
pnpm test        # run tests (vitest)
pnpm typecheck   # tsc --noEmit
pnpm check       # biome format + lint
pnpm build       # rolldown + tsc declarations

Git hooks (via husky):

  • pre-commit: staged file formatting/linting + typecheck
  • pre-push: tests

Status

Work in progress. Covers the Bash subset needed for AST-based command analysis (command classification, variable mutation tracking, guardrail enforcement). Not yet a complete POSIX/Bash parser -- notably missing: position tracking in AST nodes, extended globbing, and full arithmetic expression parsing.

License

UNLICENSED