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

regtracks

v1.0.1

Published

The JS RegTracks parser

Readme

RegTracks (JavaScript implementation)

RegTracks lets you write readable regex.

Don't know what RegTracks is? Read the super-quick introduction on the official repo!

Installation

RegTracks for JS is available via npm:

yarn add regtracks
# OR
npm install regtracks --save

Usage

Simply require or import the Track object.

const Track = require('regtracks');
// OR
import Track from 'regtracks';

If you need to define a schema in JS, you should use String.raw, so that everything is taken literally - escapes are handled by the RegTracks parser:

const schema = String.raw`
  @my_pattern
  ||
  start
  or (,)
  any a to z, A to Z, digit as ident
    times forever
  ||
`;

Then create a Track from your schema:

const myPattern = new Track(schema);

You can now make matches using either match or test:

let testText = 'hello,world,34,55,chees3';

let result = myPattern.match(testText, 'my_pattern');

This will give a result object like:

{
  match: 'hello',
  index: 0,
  collected: {
    ident: 'hello'
  }
}

To loop over all the matches, you can use the global flag and a while loop:

let result;
let options = {
  global: true,
};

while (result = myPattern.match(testText, 'my_pattern', options)) {
  console.log(result.collected.ident);
}

This will give you:

hello
world
34
55
chees3

test in place of match can be invoked exactly the same, with the same options, but returns only true and false based on whether it matched or not.

replace will replace any matches with a given replacement string.

For a more detailed API description, please see below.

API

class Track(schema: string)

The Track object is a compiled RegTracks schema which can be executed on a string. If your schema is ill-formed, the Track constructor will throw an error.

Track.match(string: string, entryPoint: string, options?: object, variables?: object)?: object

Finds matches in the given string for the pattern defined under the identifier entryPoint in the Track's schema.

Options is an object with the format:

{
  global: bool
}

global defaults to false for this method. If the global option is set to true, the next time a function of Track is called, it will begin matching from the point immediately after the one where it last found a match.

variables is any object with variable-name: value pairs which will be subsituted into the schema.

This function returns an object of the form:

{
  match: string,
  index: number,
  collected: {
    identName: string
  }
}

where:

  • match is the full string that was matched by the pattern at entryPoint
  • index is the index in the string that the match begins at
  • collected is an object with ident-name: value pairs for strings collected during matching under the as directive

Track.test(string: string, entryPoint: string, options?: object, variables?: object): bool

Returns whether a match can be found in the given string for the pattern defined under the identifier entryPoint in the Track's schema.

Options is an object with the format:

{
  global: bool
}

global defaults to false for this method. If the global option is set to true, the next time a function of Track is called, it will begin matching from the point immediately after the one where it last found a match.

variables is any object with variable-name: value pairs which will be subsituted into the schema.

This function returns true if a match could be found, and false otherwise.

Track.replace(string: string, entryPoint: string, replacementString: string, options?: object, variables?: object): string

Returns a string with matches (for the pattern defined under the identifier entryPoint in the Track's schema) replaced by the given string.

The replacementString may contain references to collected strings in the format $(collectionIdent). If a string has been collected using as during matching, it will be subsituted for the ident if specified like this in the replacementString. No substitution will be made for this format if no such ident exists.

Options is an object with the format:

{
  global: bool
}

global defaults to true for this method. If the global option is set to true, the next time a function of Track is called, it will begin matching from the point immediately after the one where it last found a match.

variables is any object with variable-name: value pairs which will be subsituted into the schema.

This function returns the string with subsitutions made if possible.

Contributing

Contributions are very much welcomed! Please, fork and make a PR. Issues are also appreciated.

This package uses yarn. Install with yarn. Run tests with yarn test.