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

reflect-type-3

v1.0.0

Published

Parser for a simplified, regular subset of JavaScript regex

Readme

Build status

A parser for a simplified, regular subset of JavaScript regular expressions that doesn’t support capturing.

Because it’s regular, the subset doesn’t support:

  • backreferences

Because it doesn’t support capturing, it doesn’t support:

  • capturing groups ((…) unless (?:…))
  • greediness modifiers

Because it’s simplified, it doesn’t support:

  • assertions (anchors, word boundaries, (?=…), and (?!…))
  • escapes with easy alternatives that are obscure (\cX), uncommon (\f, \v), or syntactically awkward (\0)
  • escapes that aren’t necessary in any context
  • \s and \S (what they match is not obvious)

Syntax

When syntactically valid, a pattern has the same meaning as it does in JavaScript (i.e. when passed to the RegExp constructor) with no flags.

pattern = disjunction

disjunction = alternative [ "|" disjunction ]

alternative = *term

term = atom [ quantifier ]

quantifier =
    "*" /                      ; zero or more
    "+" /                      ; one or more
    "?" /                      ; zero or one
    "{" *DIGIT "}" /           ; exactly count. counts are at most Number.MAX_SAFE_INTEGER.
    "{" *DIGIT ",}" /          ; at least count
    "{" *DIGIT "," *DIGIT "}"  ; at least first count and at most second. must be a non-empty range.

atom =
    pattern-character /        ; the character itself
    "." /                      ; any character except CR, LF, U+2028, and U+2029
    "\" atom-escape /
    character-class /
    "(?:" pattern ")"

character-class =
    "["
    [ "^" ]                    ; indicates a negated character class
    *range
    "]"

range =
    range-character "-" range-character /  ; must be a non-empty range
    range-character /
    "\" predefined-range

range-character =
    range-plain-character /
    "\" range-escape

character-escape =
    "n" /                      ; LF
    "r" /                      ; CR
    "t" /                      ; tab
    "x" 2hex-digit /
    "u" 4hex-digit

predefined-range =
    "d" / "D" /                ; [0-9], [^0-9]
    "w" / "W"                  ; [0-9A-Za-z_], [^…]

atom-escape =
    character-escape /
    predefined-range /
    pattern-metacharacter /
    "/"

range-escape =
    character-escape /
    range-metacharacter /
    "/" /
    "["

range-metacharacter =
    "^" / "\" / "-" / "]"

pattern-metacharacter =
    "^" / "$" / "\" / "." / "*" / "+" / "?" /
    "(" / ")" / "[" / "]" / "{" / "}" / "|"

hex-digit =
    HEXDIG /                   ; 0-9A-F
    %x61-66                    ; a-f

pattern-character is any UTF-16 code unit that is not a pattern-metacharacter. Similarly, range-plain-character is any UTF-16 code unit that is not a range-metacharacter.

Parser output format

Every node has a type property (a string). The node types and their properties are:

Disjunction

  • alternatives, a non-empty array of Alternative nodes

Alternative

  • terms, an array of Term nodes

Term

  • atom, a Character, CharacterClass, or Disjunction node
  • quantifier, null or an object with the following properties:
    • min, the minimum number of repetitions indicated by the quantifier; an integer from 0 to 2^53−1
    • max, the maximum number of repetitions indicated by the quantifier; an integer from min to 2^53−1, or Infinity

Character

  • value, an integer UTF-16 code unit

CharacterClass

  • negated, a boolean
  • ranges, an array of objects with inclusive integer start and end properties representing UTF-16 code units

Nodes can be modified safely.

API

.parse(string)

Returns a Disjunction node or throws a PatternError.

.PatternError

The type of error thrown by .parse.

Example

const ret3 = require('reflect-type-3');

ret3.parse(/[ab]+/.source)
({
    type: 'Disjunction',
    alternatives: [{
        type: 'Alternative',
        terms: [{
            type: 'Term',
            atom: {
                type: 'CharacterClass',
                negated: false,
                ranges: [
                    {start: 97, end: 97},
                    {start: 98, end: 98},
                ],
            },
            quantifier: {
                min: 1,
                max: Infinity,
            },
        }],
    }],
})