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

rewrap

v0.1.0

Published

a tool for better regexp

Readme

rewrap

a regexp wrapper, less pain and more fun with regexp :)

feature

  • compose the regexp by string, regexp, rewrap object
  • compositional method
  • refer to the predefined regexp
  • get match by named path

document

install

npm install rewrap

dist/rewrap.js and dist/rewrap.min.js can be used in the browser

example


    const rewrap = require('rewrap');

    const {re, wrap} = rewrap; // wrap is the same as rewrap;

    // This npm package contains some frequently used regexp.
    // It can be used as the registry for rewrap.
    const reBuiltins = require('regexp-frequent');
    rewrap.registry(reBuiltins);

    re(/^/)    // /^/
    
      .ref('digits')    // /^[0-9]+/
      
      .and(/abc/)    /^[0-9]+abc/
      
      .or(/bc/, /cd/)   // /^[0-9]+abc|bc|cd/
      
      // because the line below is leaded by re, 
      // so @digits will not refer to registry, 
      // and will generate regexp as is.
      .and(/@digits/)   // /^[0-9]+abc|bc|cd@digits/
            
      .wrap   // now switch to rewrap style
      
      // @digits will refer to registry, will be replaced by [0-9]+
      // necessary () is added automatically for or expression
      .and(/@digits/)   // /(?:^[0-9]+abc|bc|cd)@digits[0-9]+/
      
      // &a indicate that a will become (a) 
      // and will be saved as result.$$rewrapData.a while matching
      .and(/a&a/)   // /^[0-9]+abc|bc|cd@digits[0-9]+(a)/
       
      .and(
      
         // generate (xy)
         // will be saved as result.$$rewrapData.xy while matching
         // same as wrap(/(xy)&xy/)
         wrap('x').and('y').save('xy')    // /(xy)/
        
      ) //   /(?:^[0-9]+abc|bc|cd)@digits[0-9]+(a)(xy)/

      // the whole above will be saved as result.$$rewrapData. part1 while matching
      .save('part1')

      // add current rewrap to registry as sample
      .register('sample')

      // refer to sample
      .rewrap(/@sample/)    // /((?:^[0-9]+abc|bc|cd)@digits[0-9]+(a)(xy))((?:^[0-9]+abc|bc|cd)@digits[0-9]+(a)(xy))/

compositional method

  • rewrap, regexp, or, and, paren, not, lookAhead, optional, any, some, repeat, times, timesMore, headTail, head, tail

they have no side effects, i.e. they always generate a new Rewrap object.

  • not, lookAhead, optional, any, some, repeat, times, timesMore

These methods can with/without an item argument, If without an item argument, it will operate on itself(this) and return a new Rewrap object.

register, ref, @path%

someRewrap.register(registry)
someRewrap.register(refPath, value)
someRewrap.register(refPath): value is someRewrap itself
someRewrap.register({refPath:value, ...}): register multiple refPath:value pairs

someRewrap.ref(refPath): use the predefined rewrap in the registry(someRewrap._registry)
someRewrap.and(/@refPath%/): use the predefined rewrap in the registry(someRewrap._registry)

refPath is like x, y, a.b.c, _a, a0.b1._c % can be omit if the following char is not identifier chars [_A-Za-z0-9]
NB. $ is not allowed in the refPath or dataPath(see below).

save, &dataPath%

someRewrap.save(dataPath): same as /@someRewrap&dataPath%/
dataPath is like x, y, a.b.c, _a, a0.b1._c
% can be omit if the following char is not identifier chars [_A-Za-z0-9]
If necessary, () will be added around someRewrap to generate a sub match.

options method

flags, registry

switch source style

someRewrap.re: lead the regexp style chain. In regexp style, @refPath%

someRewrap.wrap: lead the rewrap style chain

show me the code

Please dive into the code for more information. The code is simple and intuitive.

two npm packages work with rewrap

regexp-frequent

The npm package regexp-frequent contains some frequently used regexp. It can be used as the registry for rewrap.

rewrap-patch

The npm package rewrap-patch does monkey patch on String.prototype, make the methods(match, search, split, replace) works better with rewrap. Most of time you do NOT need rewrap-patch, except that you need the match method support someString.match(aRewrap, data).

similar npm packages

These two npm packages have similar part fearture with rewrap: save sub match with name. But rewrap is more convenient and powerful than them(no parens is necessary for name, and dot separated path is supported):
named-regexp: https://www.npmjs.com/package/named-regexp
named-js-regexp: https://www.npmjs.com/package/named-js-regexp

LICENSE

MIT, see LICENSE