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

rexrex

v1.3.0

Published

Regex utils that rock!

Downloads

5,029

Readme

🐺 rexrex

Regular Expression utils that rock!

Create regular expressions that are composable, reusable, and commentable.

Getting started

yarn add rexrex

Utils

whole

whole('sentence to match') // -> ^sentence to match$

repeat

repeat('\\d') // -> \\d
repeat('\\d', 8) // -> \\d{8}
repeat('\\d', 1, 3) // -> \\d{1,3}
repeat('\\d', 1, Infinity) // -> \\d{1,}

numeric

Equivalent to rex.repeat.bind(null, '\\d')

alpha

Equivalent to rex.repeat.bind(null, '[A-z]')

and

and('a', 'b', 'c') // -> 'abc'

or

or('a', 'b', 'c') // -> 'a|b|c'

wildcard and extra

wildcard('.') // -> '.*'
wildcard('.', true) // -> '.*?'
extra('.', matchers.LAZY) // -> '.+?'
extra('.', false) // -> '.+'

capture

capture('\\d+?') // -> (\\d+?)

or you can name your capture group with capture(pattern, name)

capture('\\d+?', 'number') // -> (?<number>\\d+?)

group

Similar to a capture(...), but won't keep the capture within the parentheses

group('.|\\s') // -> (?:.|\\s)

look.(ahead|behind).(positive|negative)

Creates a negative or positive look-ahead

look.ahead.positive('Y') === look.ahead('Y') // -> '(?=y)'
look.ahead.negative('Y') // -> '(?!y)'
look.behind.positive('Y') === look.behind('Y') // -> '(?<=y)'
look.behind.negative('Y') // -> '(?<!y)'

regex

Equal to RegExp constructor

Matchers

  • ALPHA: '[A-z]'
  • WORD: '\\w'
  • NUMBER: '\\d'
  • WHITE_SPACE: '\\s'
  • ANY: '.'
  • START: '^'
  • END: '$'
  • LAZY: '?'

not

Matches opposite of matchers

regex(matchers.not.ALPHA) // -> '[^A-z]'

Flags

  • GLOBAL: 'g'
  • MULTI_LINE: 'm'
  • INSENSITIVE: 'i'
  • STICKY: 'y'
  • UNICODE: 'u'

Examples

See index.spec.js for all the uses!

// found in `graphql-types-drivers-license`

// Matches all New York Driver's licenses
regex(
  or(
    and(alpha(1), numeric(7)),
    and(alpha(1), numeric(18)),
    and(numeric(8, 9)),
    and(numeric(16)),
    and(alpha(8))
  )
)
// -> /[A-z]{1}\d{7}|[A-z]{1}\d{18}|\d{8,9}|\d{16}|[A-z]{8}/
// matches GraphQL queries/mutations

regex(
  and(
    capture(
      and(
        capture(or(...GQL_TYPES)),
        extra(SPACE),
        extra(WORD),
        extra(SPACE),
        wildGroup(and('on', extra(SPACE), extra(WORD)))
      )
    ),
    wildcard(SPACE),
    wildGroup(
      and(extraGroup(and('{', extraGroup(CHARS))), extraGroup(and('}', extraGroup(CHARS))))
    ),
    '}'
  ),
  flags.GLOBAL
)

// -> /((fragment|query|mutation|subscription)\s+\w+\s+(on\s+\w+)*)\s*(({(\s|\w|(".*")|:|,|\.|\)|\()+)+(}(\s|\w|(".*")|:|,|\.|\)|\()+)+)+}/g

Bonus

  • Tiny!
  • Super-readable!
  • Changes make sense!