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

read-jsonregexp

v1.0.0

Published

Read jsonRegExp string and return a RegExp for it

Readme

readJsonRegExp

Read jsonRegExp string and return a RegExp for it

Implements jsonRegExp, e.g. reads in

'a+b'

and returns

/a\+b/

or

'`(`^`|/`).git`(`/`|`$`)'

and returns

/(^|\/)\.git(\/|$)/

hh lohmann <[email protected]>

Changelog

Last 3 changes - see CHANGELOG file for full list and details

  • (1.0.0) v1.0.0

Synopsis

  import { readJsonRegExp } from 'read-jsonregexp'

Parameters

jsonRegExp

String: The string to interpret as jsonRegExp

Settings

none

Returns

RegExp represention for the evaluated jsonRegExp

Examples

  • jsonRegExp without any RegExp

    const myString='k8s'
    console.log(readJsonRegExp(myString)) // /k8s/
  • jsonRegExp with RegExp for character range with RegExp metacharacters []

    const myString='k`[0-9`]s'
    console.log(readJsonRegExp(myString)) // /k[0-9]s/
  • jsonRegExp with literal []

    const myString='k[number]s'
    console.log(readJsonRegExp(myString)) // /k\[number\]s/
  • jsonRegExp with RegExp for character range including literal ^

    const myString='k`[^8`]s'
    console.log(readJsonRegExp(myString)) // /k[\^8]s/
  • jsonRegExp with RegExp for character range negated by RegExp metacharacter ^

    const myString='k`[`^8`]s'
    console.log(readJsonRegExp(myString)) // /k[^8]s/
  • jsonRegExp with RegExp with flag

    const myString='k`.s`/i'
    console.log(readJsonRegExp(myString)) // /k.s/i
    • if the part after `/ contains anything that is not a valid flag (including multiple usage of the same flag) it will be given back as a literal sequence with backtick and slash, e.g.
      const myString='k`.s`/noflags'
      console.log(readJsonRegExp(myString)) // /k.s`\/noflags/
      This substitutes (for various reasons) an error message like "invalid backtick sequence: sequence"
  • jsonRegExp with literal backtick (= backtick quoted by backtick)

    const myString='k``8s'
    console.log(readJsonRegExp(myString)) // /k`8s/

Installation

Pick for your preferred package manager:

  npm i read-jsonregexp
  pnpm i read-jsonregexp
  bun i read-jsonregexp
  # For Yarn you should double check docs for your and / or
  # current Yarn version, newer versions do not treat `i package_name`
  # as an alias for `add ...` and exclude global installations
  yarn add read-jsonregexp

Details

  • Expects a single string as input, not a JSON object or file (i.e. a corresponding JSON has to be read in / evaluated by other means, e.g. a process that uses readJsonRegExp to transform a JSON into a JavaScript object that allows RegExps as values)
  • Uses JavaScript's RegExp to evaluate and transform jsonRegExps
  • Handles the RegExp metacharacters recognized by JavaScript's RegExp:
    ^ $ \ * + ? { } ( ) [ ] |

Tests

  • Code tests to be run with Node.js / Bun available in Source Code

Source Code

License

References

hh lohmann: jsonRegExp

MDN: RegExp

MDN: Regular Expressions: Flags

MDN: Syntax characters in regular expressions