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

rerejs

v0.2.1

Published

Re-implementation of ECMA-262 (JavaScript) RegExp

Downloads

27

Readme

ReRE.js

codecov GitHub Actions status NPM version

About

ReRE.js is a framework for processing ECMA-262 (JavaScript standard) RegExp. It provides:

  • parser which constructs AST nodes from a RegExp pattern string,
  • engine which executes RegExp matching against an input string, and
  • ponyfill (or shim) which is complete and full-featured alternative of RegExp class.

ReRE.js supports the latest RegExp features:

  • look-behind assertion ((?<=...)),
  • named capture group, named back reference ((?<foo>...) and \k<foo>), and
  • Unicode property class (\p{ASCII}).

Moreover, ReRE.js supports "Additional ECMAScript Features for Web Browsers" for RegExp. It means robust, so it can parse some terrible real-world RegExp patterns correctly.

Getting Started

Install ReRE.js as dependency:

$ npm install rerejs

Then, you can start:

import {
  // A parser for `RegExp` pattern.
  Parser,
  // A compiler for parsed `RegExp` pattern node.
  Compiler,
  // A ponyfill of `RegExp`.
  RegExpCompat
} from './index';

/*
 * Usage of `Parser`.
 */

// `new Parser` with parsing pattern source and flags,
// then call `parse` method to execute parsing.
const parser = new Parser('a+', 'u');
const pattern = parser.parse();

console.log(pattern);
// => {
//     type: 'Pattern',
//     flagSet: {
//       global: false,
//       ignoreCase: false,
//       multiline: false,
//       unicode: true,
//       dotAll: false,
//       sticky: false
//     },
//     captureParens: 0,
//     names: Map(0) {},
//     child: {
//       type: 'Some',
//       nonGreedy: false,
//       child: { type: 'Char', value: 97, raw: 'a', range: [ 0, 1 ] },
//       range: [ 0, 2 ]
//     },
//     range: [ 0, 2 ]
//   }

/*
 * Usage of `Compiler`.
 */

// `new Compiler` with pattern node, then call `compile` to get `program`.
const compiler = new Compiler(pattern);
const program = compiler.compile();

// `program` is compiled regular expression pattern.
// To execute matching, invoke `exec` method.
// Note that `program` is not `RegExpCompat` instance,
// and `exec` method result is not the same as `RegExp.prototype.exec`.
console.log(program.exec('bbaaabb'));
// => Match [
//      0 [0:0] => '',
//    ]

/*
 * Usage of `RegExpCompat`.
 */

// You cau use `RegExpCompat` like `RegExp` very.
const re = new RegExpCompat('a+', 'u');

console.log(re.exec('bbaaabb'));
// => [ 'aaa', index: 2, input: 'bbaaabb', groups: undefined ]

// Also, you can pass `RegExpCompat` instance to
// `String.prototype.match`, `String.prototype.replace`
// and other methods accepts `RegExp` instance.
console.log('bbaaabb'.match(re));
// => [ 'aaa', index: 2, input: 'bbaaabb', groups: undefined ]
console.log('bbaaabb'.replace(re, 'ccc'));
// => bbcccbb

// You can write `global.RegExp = RegExpCompat;`,
// however it does not work as you expected because
// it does not override `RegExp` literals construction.

Contributing

ReRE.js is alpha quality project for now, so there are many bugs and problems. If you found something, please open an issue.

Especially such reports are needed:

  • "There is a different behavior between the browser and ReRE.js."
  • "RegExp matching goes on infinite-loop. VM Bug?"
  • "A typo in comment or error message is found."

Pull Requests are also welcome.

However I concentrate improving ReRE.js ECMA-262 compatibility for now. So, I cannot accept a feature request as soon. Notably, it is out of targets of this project that extending RegExp syntax. (e.g. support x flag like Perl regular expression)

Documents for Developer

There are few documents for now. Sorry.

License

ReRE.js is licensed under MIT license.

(C) 2020 TSUYUSATO "MakeNowJust" Kitsune