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

unbash

v2.2.0

Published

Fast 0-deps bash parser written in TypeScript

Readme

unbash

Fast 0-deps bash parser written in TypeScript

Install

npm install unbash

Usage

import { parse } from "unbash";

const ast = parse('if [ -f "$1" ]; then cat "$1"; fi');

Result:

{
  type: "Script",
  commands: [{
    type: "If",
    clause: { type: "Command", name: { text: "[" }, ... },
    then: { type: "Command", name: { text: "cat" }, ... }
  }]
}

Print

Basic opinionated printer, does not preserve whitespace or comments (except shebang):

import { parse } from "unbash";
import { print } from "unbash/print";

const ast = parse('if [ -f "$1" ]; then cat "$1"; fi');
const script = print(ast);

Result:

if [ -f "$1" ]; then
  cat "$1"
fi

unbash vs tree-sitter-bash

tree-sitter-bash is an excellent choice if you need:

  • Incremental parsing
  • CST output preserving all tokens and punctuation
  • Granular error recovery that wraps errors in ERROR nodes and continues parsing

unbash might be a good fit if you prefer:

  • AST output
  • A zero-dependency package that runs in any JS environment
  • A typed TypeScript API
  • Built-in parsing for command/process substitutions, coproc, Bash 5.3 ${ cmd; }, [[ ]], (( )), and extglob
  • Tolerant parsing that never throws and collects parse errors

unbash vs sh-syntax

sh-syntax is a WASM wrapper around the robust mvdan/sh Go parser. It is highly recommended if you need:

  • Support for multiple shell dialects (bash, POSIX sh, mksh, Bats)
  • Built-in formatting and pretty-printing (print)

unbash might be a good fit if you prefer:

  • A zero-dependency, synchronous API
  • A detailed AST with structured word parts, parameter expansions, arithmetic expressions, and test expressions

unbash vs bash-parser

bash-parser (last publish: 2017) and its fork @ericcornelissen/bash-parser (community dependency maintenance fork ❤️ now archived) might be interesting if you need:

  • A POSIX-only mode that rejects bash-specific syntax

unbash might be a good fit if you prefer:

  • A zero-dependency architecture
  • A typed TypeScript API (ESM-only)
  • Tolerant parsing that never throws and collects parse errors
  • Structured AST nodes for parameter expansions, arithmetic expressions, and [[ ]] test expressions
  • Support for many additional syntax features (like herestrings, C-style for loops, select, process substitution, etc. etc.)

Benchmarks

Relative performance comparison (on Apple M1 Pro/32GB), unbash is x times faster:

| Parser | short | advanced | medium | large | | ---------------------------- | ----: | -------: | -----: | ----: | | tree-sitter-bash (native) | 13x | 9x | 4x | 5x | | tree-sitter-bash (WASM) | 16x | 12x | 8x | 8x | | sh-syntax | 2136x | 1537x | 8x | 4x | | bash-parser | 256x | N/A | N/A | N/A | | @ericcornelissen/bash-parser | 267x | N/A | N/A | N/A |

Run the benchmarks using Node.js v22:

pnpm install
node bench/all.ts

Size

unbash is 53K minified, 13KB gzipped.

Playgrounds

License

ISC