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

ctxgrep

v0.0.3

Published

Context-aware regex matching

Downloads

2

Readme

Context-aware grep

This is a simple regex match CLI that includes all lines leading up to a match that have a lower indentation than the match itself. It has far fewer features than GNU grep. In fact, it's usage is very simple:

cat file | ctxgrep expression

or

ctxgrep expression [filename|-]

where - causes ctxgrep to read from stdin.

Example

Which dependencies of apollo-server match the expression graphql? yarn list would tell us, but would not filter. grep would filter, but would not tell us the path down the dependency tree that causes the dependency. So, we replace the box drawing characters that yarn list outputs with spaces, so we can properly count indentation, and filter with ctxgrep. This tells us not only which dependencies match graphql, but also the branch of the tree that causes the dependency.

$ yarn list | | ctxgrep -b graphql
stdin:     1:yarn list v1.22.19
stdin:     5:   @apollo/[email protected]
stdin:     6:      apollo-graphql@^0.4.0
stdin:    10:   @apollo/[email protected]
stdin:    22:      apollo-graphql@^0.4.0
stdin:    49:      graphql-extensions@file:packages/graphql-extensions
stdin:   101:   @apollographql/[email protected]
stdin:   103:   @apollographql/[email protected]
stdin:   967:   @types/[email protected]
stdin:   972:      [email protected] - 16
stdin:   973:      [email protected]
stdin:  1180:   [email protected]
stdin:  1182:      graphql-extensions@file:packages/graphql-extensions
stdin:  1194:   [email protected]
stdin:  1196:      apollo-graphql@^0.4.0
stdin:  1202:      graphql-extensions@file:packages/graphql-extensions
stdin:  1226:   [email protected]
stdin:  1245:   [email protected]
stdin:  1246:      @apollographql/[email protected]
stdin:  1251:      graphql-tools@^4.0.0
stdin:  1252:      [email protected]
stdin:  1285:   [email protected]
stdin:  1286:      @apollographql/[email protected]
stdin:  1290:      graphql-tools@^4.0.0
stdin:  1291:      [email protected]
stdin:  1301:   [email protected]
stdin:  1302:      @apollographql/apollo-tools@^0.4.3
stdin:  1303:      @apollographql/[email protected]
stdin:  1305:      @apollographql/[email protected]
stdin:  1306:      @types/graphql-upload@^8.0.0
stdin:  1332:      graphql-extensions@file:packages/graphql-extensions
stdin:  1333:      graphql-tag@^2.9.2
stdin:  1334:      [email protected]
stdin:  1336:      graphql-tools@^4.0.0
stdin:  1337:      [email protected]
stdin:  1343:      graphql-upload@^8.0.2
stdin:  1376:   [email protected]
stdin:  1377:      @apollographql/[email protected]
stdin:  1473:      graphql-subscriptions@^1.0.0
stdin:  1474:      [email protected]
stdin:  1476:      graphql-tools@^4.0.0
stdin:  1477:      [email protected]
stdin:  1516:   [email protected]
stdin:  1517:      @apollographql/[email protected]
stdin:  1522:      graphql-subscriptions@^1.0.0
stdin:  1523:      [email protected]
stdin:  1525:      graphql-tools@^4.0.0
stdin:  1526:      [email protected]
stdin:  1532:   [email protected]
stdin:  1533:      @apollographql/[email protected]
stdin:  1538:      graphql-subscriptions@^1.0.0
stdin:  1539:      [email protected]
stdin:  1541:      graphql-tools@^4.0.0
stdin:  1542:      [email protected]
stdin:  1551:   [email protected]
stdin:  1552:      @apollographql/[email protected]
stdin:  1563:      graphql-subscriptions@^1.0.0
stdin:  1564:      [email protected]
stdin:  1566:      graphql-tools@^4.0.0
stdin:  1567:      [email protected]
stdin:  1579:   [email protected]
stdin:  1580:      @apollographql/[email protected]
stdin:  1586:      graphql-tools@^4.0.0
stdin:  1587:      [email protected]
stdin:  1593:   [email protected]
stdin:  1594:      @apollographql/[email protected]
stdin:  1611:   [email protected]
stdin:  1670:      graphql-subscriptions@^1.0.0
stdin:  1671:      [email protected]
stdin:  1673:      graphql-tools@^4.0.0
stdin:  1674:      [email protected]
stdin:  1708:   [email protected]
stdin:  1710:      graphql-extensions@file:packages/graphql-extensions
stdin:  2852:   [email protected]
stdin:  2853:      @apollographql/apollo-tools@^0.4.3
stdin:  2854:      @apollographql/[email protected]
stdin:  2879:   [email protected]
stdin:  2881:   [email protected]
stdin:  2882:   [email protected]
stdin:  2888:   [email protected]
stdin:  2901:   [email protected]

It's also useful for grepping code, because, for a given variable name, it will tell you the if-statement in which it is read/written, all the way up to the name of the function wherein the if-statement appears. Since it calculates context from the initial indentation and nothing more, it does not track multiline function definitions. So, a function definition like

int main(
  int argc,
  char **argv
) {
  int variable_name = 0;
}

would only show

) {
  int variable_name = 0;