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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tidal.pegjs

v0.0.6

Published

A parsing expression grammar for the Tidal pattern language, and associated pattern querying functions.

Readme

tidal.pegjs

tidal.pegjs is a parsing expression grammar for the TidalCycles pattern language, written using PEG.js. The goal of the PEG is to easily translate strings of Tidal patterns into annotated JavaScript data structures for use in sequencing. The project also provides a Pattern object that can be queried for events by passing start and ending times.

Usage

The easiest way to use this is by including the dist/pattern.js file in your HTML; this will provide a global Pattern object. To then process and query a pattern string:

const p = Pattern( '[0 [1 2]*4 <5 6 7> 8]' )

// start at time 0 and query for 3 cycles
const events = p.query( 0, 3 )
// events now holds the query results, but we can also
// call p.print to pretty-print them to the JS console.

p.print()

There are single-file HTML examples in the demos folder for reference.

Parsing vs. Querying

Before querying a Tidal pattern for individual events, the pattern must be parsed; this is the functionality that the parsing expression grammar provides. Once parsed, we have a data structure describing the pattern. For example, given the pattern 0 1 2 the PEG generates"

{
  values: [
    { type: 'number', value: 0 },
    { type: 'number', value: 1 },
    { type: 'number', value: 2 },
  ],
  type: 'group'
}

Once we have this data structure, we can then query the data for events. If we use the parsed data aboveand query it for one cycle of events, we get:

[
  {
    value:0,
    arc: { start: Fraction(0), end:Fraction(1,3) }
  },
  {
    value:1,
    arc: { start: Fraction(1,3), end:Fraction(2,3) }
  },
  {
    value:2,
    arc: { start: Fraction(2,3), end:Fraction(1) }
  }
]

Rational numbers are provided by the fraction.js library.

Development

Installing dependencies

To install all dependencies run npm install

Using Gulp

All files generated by using Gulp will be located in the dist folder. It is all you will need to use the files as modules to parse and flatten Tidal patterns.

If you want to modify any of the files you can run gulp watch in the background which will re-compile and run the tests automatically every time there is any modification in any of the files.

  • Compile the parser into a js module:

    • Run gulp build

    • Pass any Tidal pattern to the parse function as:

    const parser = require( './dist/peg-parse.js' ); // Modify path to this file if necessary
    
    parser.parse(' 1 2 3 ')

    The peg-parse.js file can be required as a module in Node.js or in the browser using browserify, etc.

    For more instructions on compiling parsers, see https://pegjs.org/documentation#generating-a-parser-javascript-api.

  • Run the mocha tests: gulp test

  • Watch for changes in any file or tests and run tests automatically whenever this happens: gulp watch

  • Clean everything that was generated with gulp from the dist folder: gulp clean

Without using Gulp

It's recommended to use Gulp since the tasks are clearly defined and the resulting files in the dist folder are pretty much all you need, but here are instructions to work without it as well.

Installing dependencies

We haven't done any work making this tidy yet, but will try to do so soon. For now, installing the dependencies can be done with: npm install pegjs -g

For testing you'll also need npm install mocha -g

Compiling the parser

To compile the parser into a JS module, use pegjs tidal.pegjs in the top-level directory of this repo. This will create a file named tidal.js that can be required as a module in Node.js or in the browser using browserify etc.

To compile the parser as a global variable: pegjs --format globals --export-var Tidal tidal.pegjs.

For more instructions on compiling parsers, see https://pegjs.org/documentation#generating-a-parser-javascript-api.

Testing

Tests are done with Mocha, you'll need to have it installed globally. You should also have peg.js installed locally: npm install pegjs

Then run mocha from the top-level directory to run the parsing tests.

Issues

There are still some issues with this project, which can be found in the TODO.md file. If you see anything else and fix it feel free to create pull requests.

More about PEGs and musical programming languages

Graham Wakefield and Charlie Roberts ran a workshop on using PEGs to create musical programming languages; check it out for more about how PEGs work and tutorials on creating your own mini-languages.

Credits

This library is developed by Charlie Roberts and Mariana Pachon Puentes.