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

parleur-js

v1.1.1

Published

A library for building text parsers

Downloads

16

Readme

parleur.js

A JavaScript library for building text parsers. It is inspired by the parser combinator libraries known from functional programming, such as Parsec.

parleur.js is simple to use and very general. It should be able to handle pretty much any parsing job you throw at it. Unlike parser generators, like the traditional Yacc library, parleur.js is able to parse context dependent formats.

Quick Introduction

I will now walk you through parsing a simple expression using parleur.js. We're going to parse a "variable assignment" like var foo = 42.

First we create a Parleur.Parser object with the text we want to parse:

var parser = new Parleur.Parser("var foo = 42");

We then add calls to parse rules. A parse rule can be very simple or very complex, but always work the same: the look for some pattern at the start of the text, if they succeed they remove the pattern from the text and return it, if they fail they return undefined and put the parser into error state.

Lets just see how it looks:

var parser = new Parleur.Parser("var foo = 42");
parser.string("var");
parser.space();
var name = parser.regex("[a-zA-Z]+");
parser.space();
parser.string("=");
parser.space();
var value = parser.int();
parser.end();

You should notice that the parser.<rule> calls follow our text closely. We should still explain them though:

  • parser.string("var") parses the exact string "var" and returns the result.
  • parser.space() parses one or more space characters.
  • parser.regex("[a-zA-Z]+") parses a match for the pattern [a-zA-Z+] -- the name of our variable.
  • parser.int() parses a positive integer.
  • parser.end() parses nothing, but checks that there is no more text left to parse.

If everything went well then we should have name = "foo" and value = 42. If one of the rules failed the results will be undefined.

To check that the parsing succeeded we call parser.success(), and we can then use the parsed values to build our own return value:

var parser = new Parleur.Parser("var foo = 42");
parser.string("var");
parser.space();
var name = parser.regex("[a-zA-Z]+");
parser.space();
parser.string("=");
parser.space();
var value = parser.int();
parser.end();

if (parser.success()) {
  return { name: name, value: value }
}

For good measure we should put or parser inside a function:

function parseVariable(text) {
  var parser = new Parleur.Parser(text);
  parser.string("var");
  parser.space();
  var name = parser.regex("[a-zA-Z]+");
  parser.space();
  parser.string("=");
  parser.space();
  var value = parser.int();
  parser.end();

  if (parser.success()) {
    return { name: name, value: value }
  }

  throw parser.errorMessage();
}

If we get to the throw statement it means that the parsing has failed. Calling parser.errorMessage() will return a string telling you exactly why and where the parser failed.

For more examples of how to use parleur.js take a look at the tests in test/ .

Contributing

The API should be pretty stable now, so the best way to contribute is to use parleur.js for something. By using it we will be able to figure if anything is missing or anything should be removed -- or if parleur.js is usable at all.

You can also read through the source code and see if you can spot places where performance or maintainability could be improved.