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

@tabnas/railroad

v0.2.0

Published

Railroad (syntax) diagram renderer for the tabnas parser.

Readme

@tabnas/railroad

Railroad (syntax) diagram renderer for the tabnas parser.

Point it at a tabnas instance that already has a grammar installed and it introspects the rules and emits three artifacts:

  • a declarative JSON model of the grammar (the interchange format),
  • a vertical-flow SVG (one linked, anchored track per rule),
  • a vertical ASCII diagram.

Diagrams bias toward verticality (tall and narrow) so they read well on laptop browsers and phones: sequences run top-to-bottom, choices fan out sideways, and optional / repetition rails run on the side.

Install

npm install @tabnas/parser @tabnas/railroad

Use as a plugin

Load a grammar plugin (here @tabnas/json) and railroad, then read the grammar back out and render it:

const { Tabnas } = require('@tabnas/parser')
const { json } = require('@tabnas/json')
const { railroad } = require('@tabnas/railroad')

const tn = new Tabnas({ plugins: [json, railroad] })
const model = tn.railroad.toJson()

model.start                              // => 'val'
Object.keys(model.rules).length          // => 5
tn.railroad.toSvg().startsWith('<svg')   // => true
  • tn.railroad() / tn.railroad.toJson() — the GrammarModel for this instance.
  • tn.railroad.toSvg(opts?) — whole-grammar SVG.
  • tn.railroad.toAscii(opts?) — whole-grammar ASCII ({ ascii: true } for plain | - +).

Documentation

Four-quadrant Diátaxis docs:

The Go port lives in ../go (see ../go/README.md).

Sample output

@tabnas/json rendered to a vertical-flow diagram (tabnas-railroad --grammar @tabnas/json -o examples):

railroad diagram of the @tabnas/json grammar

The same grammar as an ASCII diagram (excerpt — val, map, pair; full output in ../examples/json-grammar.txt):

val:
              │
   ┌──────────┼──────────┐
┌──┴──┐   ┌───┴──┐   ╭───┴───╮
│ map │   │ list │   │ "VAL" │
└──┬──┘   └───┬──┘   ╰───┬───╯
   └──────────┼──────────┘
              │

map:
        │
     ╭──┴──╮
     │ "{" │
     ╰──┬──╯
        │
    ┌───┴──┐
┌───┴──┐   │
│ pair │   │
└───┬──┘   │
    └───┬──┘
        │
     ╭──┴──╮
     │ "}" │
     ╰──┬──╯
        │

pair:
    │
    ├────┐
╭───┴───╮│
│ "KEY" ││
╰───┬───╯│
    │    │
 ╭──┴──╮ │
 │ ":" │ │,
 ╰──┬──╯ │
    │    │
 ┌──┴──┐ │
 │ val │ │
 └──┬──┘ │
    ├────┘
    │

The JSON model

{ start: string, rules: { [name]: Node }, meta: { engine: 'tabnas' } }

Node is a small tagged union — terminal / nonterminal / comment / skip / seq / choice / optional / oneOrMore / zeroOrMore. It is pure data, so the SVG and ASCII are fully reproducible from the JSON alone. The constructors and a text form are exported for direct use:

const { toText, Sequence, Choice, Optional } = require('@tabnas/railroad')

toText(Sequence('GET', Optional('path')))   // => '"GET" ["path"]'
toText(Choice('hi', 'hello'))               // => '("hi" | "hello")'

CLI

# introspect a grammar plugin and write json + svg + ascii into ./diagrams
tabnas-railroad --grammar @tabnas/json -o diagrams

# render a saved model
tabnas-railroad -f diagrams/grammar.railroad.json --ascii

Scope

This renderer introspects @tabnas/parser (Tabnas) instances. The @tabnas/ini and @tabnas/yaml grammars target the older @tabnas/jsonic engine and are not yet supported (a jsonic introspection adapter is deferred).

License

MIT.