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 🙏

© 2024 – Pkg Stats / Ryan Hefner

parexgram-js

v0.2.6

Published

Parsing Expression Grammar for JS

Downloads

7

Readme

parexgram.js

🔠 Parsing Expression Grammars for JS

NPM

HitCount

| Platform | Build Status | | --- | --- | | Linux | Build Status | | Windows | Build status |

codecov

Known Vulnerabilities devDependencies Status

Install

NPM

npm i parexgram-js

CDN

<script style="https://cdn.jsdelivr.net/npm/parexgram-js/dist/index.min.js"></script>

Usage

Loading the module

CommonJS

const Parexgram = require('parexgram-js');

Browser

The Browser version provides an object named 'Parexgram' which you can use to access the provided classes.

Using the classes

Feed

Feed serves as the consumable string for the Parexgram. Matchers relies on a Feed for extracting/consuming strings. If a Matcher successfully consumes the Feed prefix, the Feed value changes.

const feed = new Feed('some expression');

CharSet

CharSet is a Matcher class which extracts an exact sequence of a string from the Feed prefix.

If a CharSet attempts to consume the Feed, it will return the exact match if the match was successful, otherwise, the CharSet will return an undefined result.

const feed = new Feed('some expression');
console.log(new CharSet('some').parse(feed)); // some

Range

Range is a Matcher class which extracts a single character from the Feed prefix if the character lies within the Character range.

If a Range attempts to consume the Feed, it will return the character that matches, otherwise, undefined is returned.

const feed = new Feed('some expression');
console.log(new Range('a', 'z').parse(feed)); // s

Sequence

Sequence is a Matcher class which extracts an exact sequence of matches given a sequence of matchers from a Feed prefix.

If a CharSet attempts to consume the Feed, it will return the exact matches inside of an array if the match was successful, otherwise, the CharSet will return an undefined result.

const feed = new Feed('some expression');
const alpha = new Range('a', 'z');
console.log(new Sequence([alpha, alpha]).parse(feed)); // ['s', 'o'];

Alternation

Alternation is a Matcher class which extracts an exact match given a sequence of matchers from a Feed prefix. Unlike Sequence, Alternation will only return one of the matchers result.

const feed = new Feed('some expression');
const alpha = new Range('a', 'z');
console.log(new Alternation([alpha, alpha]).parse(feed)); // 's';

Quantifier

Quantifier is a Matcher class which extracts a series of matches by a given matcher from a Feed prefix. Given a range, if a Quantifier collects an amount of matches between the given range, the Quantifier returns an array of those matches, whereas if the Quantifier collects an amount less than the minimum boundary of the range, the Quantifier returns undefined.

const feed = new Feed('some expression');
const alpha = new Range('a', 'z');
console.log(new Quantifier(alpha, 0).parse(feed)); // ['s', 'o', 'm', 'e']

Pattern

Pattern is a Matcher class which extracts the Feed prefix if it matches the RegExp provided.

const feed = new Feed('some expression');
console.log(new Pattern('[a-z]+').parse(feed)); // ['s', 'o', 'm', 'e']

Matcher

Matcher is an interface used for the above classes. This signifies that the object can consume a Feed prefix. You can extend the Matcher to create your own custom Matcher.

Documentation

Online Documentation can be found at the official Doc Site.

Examples

Build

Clone the repo then run:

npm install

To build the docs, coverages, commonjs and browser module:

npm run build

Changelogs

0.2.0

  • Feed.peek(undefined) returns the rest of the Feed string.
  • Pattern class which allows the use of RegExp for matching Feeds.