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

@carlosvpi/parser

v1.0.5

Published

Parsing utility

Readme

@carlosvpi/parser

A <6kB Parsing utility

Install

npm install @carlosvpi/parser

yarn add @carlosvpi/parser

Parse a string

Import the parser

const getParser = require('@carlosvpi/parser')
import getParser from '@carlosvpi/parser'

Use the parser

const grammar = `
  S = 's' A | '0';
  A = 'a' S;
`
const parser = getParser(grammar)

parser is a hash. Each rule head of the grammar is a key in the hash. In this case,

typeof parser.S === 'function'
typeof parser.A === 'function'

If the string head is the head of a rule, and input is some string, then

parser[head](input)

parses the input using the given grammar, using the head as an axiom. The output of parser[head](input) is a parsed tree.

The grammar

The grammar that the getParser function (from @carlosvpi/parser) takes is a string that follows the same syntax described in the Wikipedia page for EBNF.

The tree

The result of parser[head](input) is a tree where nodes have this shape:

[node, endIndex, errors]

endIndex is the las index of the input that has been parsed. If it does not equal the length of the input, it means that the rest of the input does not follow the grammar.

errors is a list of strings, each indicating a possible error during the parsing. Erros have this shape: "✘ 2:12 | Expected 'non-terminal W', got 'rest of input"

The node is a pair [root, ...children], where root is a string with these possible values:

  • '$LITERAL': has only one child, the parsed literal as a string,
  • '$MATCH': its children are the result of applying a regex to the input using js regex match,
  • '$CONCAT': its children are other nodes as an array,
  • head: this node corresponds to the parsing the input using a rule head

Example

This code

parser(`
  S = 's' A | '0';
  A = 'a' S;
`).S('sasa0')[0]

produces this tree:

[
   "S",
   [
      "$CONCAT",
      [
         "$LITERAL",
         "s"
      ],
      [
         "A",
         [
            "$CONCAT",
            [
               "$LITERAL",
               "a"
            ],
            [
               "S",
               [
                  "$CONCAT",
                  [
                     "$LITERAL",
                     "s"
                  ],
                  [
                     "A",
                     [
                        "$CONCAT",
                        [
                           "$LITERAL",
                           "a"
                        ],
                        [
                           "S",
                           [
                              "$CONCAT",
                              [
                                 "$LITERAL",
                                 "0"
                              ]
                           ]
                        ]
                     ]
                  ]
               ]
            ]
         ]
      ]
   ]
]