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 🙏

© 2026 – Pkg Stats / Ryan Hefner

jsregexphelper

v1.2.6

Published

Helper method for JS regular expressions

Readme

[!IMPORTANT] This repository is moved to Codeberg.org.

For now it is kept in sync with the original repository @Github.

Depending on future USA/Microsoft/Github policies the Github version maybe discontinued later.

In other words, starting july 12 2025 the Codeberg repository is authorative.

RegexHelper

A module to create JS regular expressions with comments and whitespace using a tagged template

Import

import $RE from "[location of RegexpCreator.js]";

Syntax

const noCommentRE = $RE`
  // -------------------------------------------------------------------
  //  this regular expression finds all comment sections in a JS-string
  // -------------------------------------------------------------------
  \/\* ( ?: [^*] | \*+[^*\/] ) *\*+\/ // multiline (/* ... */)
  |                                   // or
  ( ?<!:|\\\|' ) \/\/.*               // single line (// ...)`;

// noCommentRE => /\/\*(?:[^*]|\*+[^*\/])*\*+\/|(?<!:|\\\|')\/\/.*/gm

const cleaned = "Hello world /* no comment */\nHello // no world"
  .replace(noCommentRE.flags(`g`), ``)

// cleaned => Hello world\nHello

escape

The imported function (here $RE) has a static escape method to escape strings for a regular expression.

It either uses the new (generally available) RegExp.escape or a proprietary escape method for older browsers.

  $RE.escape(`Hello (world)`); // result => 
  // using RegExp.escape: "\x48ello\x20\(world\\)"
  // using proprietary method: "\Hello\x20\(world\)";

flags

A $RE-instance is actually a Proxy. It can be used as a regular expression, but also contains a flags method and a getter (re) for the actual regular expression value.

The [$RE instance].re getter return the actual RegExp instance.

Flags can be added using the instance flags method [$RE RegEx instance].flags([flags:string]) or (legacy) by adding an Array of flag strings as last replacement in the template string e.g. $RE`[ABZ].+ ${["g", "u"]}` .

To remove all current flags, use [$RE RegEx instance].flags("-r").

The flags method is chainable. So [$RE RegEx instance].flags("-r").flags("gm") removes current flags from the instance and re-adds gm.

Replacing flags in the instance can be accomplished using the above mentioned (chaining) or [$RE RegEx instance].flags("-r|[new flags]") (so remove current flags -r, then add |[new flags], e.g. [$RE RegEx instance].flags(-r|iu).

Notes

  • The replacement value must be the last replacement in the template string.
  • The given flags are checked and cleaned

plain spaces

To insert a plain space (so not a whitespace) use <!32>

const hiRE = $RE`
    Hello<!32> /* <= this will be a plain space in the result */ {1,} 
    .*`.flags(`gi`);
// hiRE => /Hello {1,}.*/gi 
const hi = hiRE.test("hello    world!"); 
// hi => true

Or use $re.escape

const hiRE = $RE`
    Hello${$re.escape(` `)} /* <= this will be \x20 in the result */ {1,} 
    .*`.flags(`gi`);
// hiRE => /Hello\x20{1,}.*/gi

hiRE.test("hello    world!"); // => true

Demonstration/examples.