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

storybook-parser-utils

v1.0.1

Published

Utility library that parses JavaScript files for Storybook.

Readme

How to use

const {getStories} = require('storybook-parser-utils');

const stories = getStories(fileAsString);
// [
//   {
//     kind: 'Card',
//     story: 'Basic',
//     location: { line: 10, column: 4 }
//   },
//   {
//     kind: 'Card/Atoms',
//     story: 'Card Divider',
//     location: { line: 67, column: 4 }
//   },
//   // ...
// ]

Run npm run test to see this output, and play around with the input in ./story-parser-acorn.test.js for more testing.

Overview

Shift AST spec is the best one out there (in my opinion). Downside is there isn't a huge amount of community behind it. This means there aren't a lot of plugins, and so parsing JSX is extremely difficult.

Acorn is alright and way more popular; I think this is what Babel uses under the hood in many places. It's easy to parse JSX as well using one of their plugins.

Because of those two reasons, we use Acorn for this job. Luckily, the difference is very subtle in our traversing strategy, but getting locations is a bit more involved (not too complicated though).

Traversing Algorithm

The overall traversing algorithm for both Shift and Acorn AST's; note that they are almost identical (luckily).

Shift Parser

Look for a CallExpression and enter this recursive routine:

(1) Looking at a CallExpression

callee     ->   If `StaticMemberExpression`, then proceed to step (2)
                  This being a `StaticMemberExpression` is a candidate for `add` because `add` cannot be called on its own
callee     ->   If `IdentifierExpression`, then proceed to step (3)
                  This being a `IdentifierExpression` is a candidate for `storiesOf`
arguments  ->   the arguments to the function call, aka our "Story" or our "Kind"

(2) Then we enter the callee which is a StaticMemberExpression

object    ->  if `CallExpression`, repeat logic above for `CallExpression`
property  ->  must be `add` or else this node isn't useful to us

(3) Then we enter the callee which is an IdentifierExpression

name  ->  must be `storiesOf` or else this node isn't useful to us

Acorn Parser

Look for a CallExpression and enter this recursive routine:

(1) Looking at a CallExpression

callee     ->   If `MemberExpression`, then proceed to step (2)
                  This being a `MemberExpression` is a candidate for `add` because `add` cannot be called on its own
callee     ->   If `Identifier`, then proceed to step (3)
                  This being a `Identifier` is a candidate for `storiesOf`
arguments  ->   the arguments to the function call, aka our "Story" or our "Kind"

(2) Then we enter the callee which is a MemberExpression

object    ->  if `CallExpression`, repeat logic above for `CallExpression`
property  ->  must be `add` or else this node isn't useful to us

(3) Then we enter the callee which is an Identifier

name  ->  must be `storiesOf` or else this node isn't useful to us