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

cgrep

v2.2.1

Published

cgrep is an npm package for writing project checks with regex.

Readme

cgrep

cgrep is an npm package for writing project checks with regex.

It includes

  • A command, yarn cgrep, which runs all project checks against all project files.
  • An extended regex grammar for finding code patterns.
yarn add -D cgrep

command

> yarn cgrep -h
Usage: cgrep [options]

Checks project files against cgrep rules.

Options:
  -V, --version         output the version number
  -s, --staged          only check git staged files
  -d, --debug           print debug information
  -p, --project <path>  path to tsconfig.json
  -g, --glob <pattern>  only check files matching glob pattern
  --cwd <path>          set the current working directory
  -h, --help            display help for command

On run, cgrep will

  1. Load all checks from cgrep.config.[ts,js] in the project root.
    • All publicly exported functions will be registered as a check. For example,
      import { cgrep, CGrepCheckArgs } from 'cgrep';
      export function avoidFooModule({ underline }: CGrepCheckArgs) {
          underline(
              cgrep`import $$ from 'foo'`,
              "Do not use foo module, prefer bar.",
              "warn");
      }
  2. Each check will be run against all project files. .gitignore is respected. If a check returns boolean false or the string fail, the cgrep command will have a failure exit code.
    • Each check is passed the following args as an object:
      /** Eg 'src/components/foo.js'. Relative posix path format. */
      filePath: string;
      
      /** Eg 'example.js' */
      fileName: string;
      
      /** Eg '.js' */
      fileExtension: string;
      
      /** Eg 'console.log("hello world");' */
      fileContents: string;
      
      /** Function to underline a string or regexp in `fileContents` and log it to console. */
      underline: (
          regexOrText: RegExp | string,
          message: string,
          alert?: 'error' | 'warn' | 'info'
      ) => void;

cgrep can be plugged in as part of a lint step in CI:CD or as a git commit hook.

module

cgrep exports typings and one string interpolation function, cgrep.

cgrep returns a standard RegExp object with two extra functions, matchFirst and matchAll. You can think of it as regex specifically for JavaScript code.

$a: match any variable.
$1: match any literal.
$@: match any operator.
$#: match any keyword.
$$: match any block (non-greedy).
$$$: match any block (greedy).
REGEX(): match any regex.

Let's look at some examples.

cgrep`if ($a == $b) { return $c; }`
    matches:
        1. if (foo == bar) {
            return baz;
        }
        2. if (apple==orange){return banana;}
cgrep`$1 + $2 + $3`
    matches:
        1. 44 + "hello world" + 3.14159
        2. 1 + 2 + 3
        3. 1 + 1 + 1
cgrep`if (a $@ b)`
    matches:
        1. if (a + b)
        2. if(a-b)
        3. if(a   <  b)
cgrep`$# (true)`
    matches:
        1. while (true)
        2. if ( true )
cgrep`do { $$ } while(true)`
    matches
        1. do {
            console.log(foo);
            log("cool");
        }   while  (true)
        2. do {} while(true)
cgrep`REGEX(3+9+2*) 5 + 5`
    matches
        1. 392225+5

There is a live cgrep expression playground here.
You can also view the test suite for more examples.