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

xgrep

v0.3.0

Published

Ultra-fast indexed code search engine powered by trigram index. Native Rust bindings for Node.js.

Downloads

51

Readme

xgrep

Ultra-fast indexed code search engine for Node.js. Powered by trigram inverted index in Rust via napi-rs.

27-59x faster than ripgrep on repeated searches.

Install

npm install xgrep

Pre-built binaries are available for:

  • Linux (x86_64, ARM64)
  • macOS (x86_64, ARM64)
  • Windows (x86_64)

Usage

import { Xgrep } from 'xgrep';

// Open a directory and build the index
const xg = Xgrep.open('/path/to/your/repo');
xg.buildIndex();

// Search for a pattern
const results = xg.search('fn main');
for (const r of results) {
  console.log(`${r.file}:${r.lineNumber}: ${r.line}`);
}

// Search with options
const filtered = xg.search('TODO', {
  fileType: 'ts',          // Filter by file type
  caseInsensitive: true,   // Case-insensitive search
  maxCount: 10,            // Limit results
  pathPattern: 'src/',     // Filter by path
});

// Regex search
const regexResults = xg.search('fn\\s+\\w+', { regex: true });

// Index status
console.log(xg.indexStatus());

API

Xgrep.open(root: string): Xgrep

Open a directory for searching. Index location is auto-resolved to ~/.cache/xgrep/.

Xgrep.openLocal(root: string): Xgrep

Open with local index storage (.xgrep/ in the project root).

xg.buildIndex(): void

Build or rebuild the search index.

xg.search(pattern: string, opts?: SearchOptions): SearchResult[]

Search for a pattern in the indexed codebase.

SearchOptions:

| Option | Type | Default | Description | |--------|------|---------|-------------| | caseInsensitive | boolean | false | Case-insensitive search (ASCII-only) | | regex | boolean | false | Treat pattern as regex | | fileType | string | - | Filter by file type (e.g., "rs", "py", "js") | | maxCount | number | - | Maximum number of results | | changedOnly | boolean | false | Only search git-changed files | | since | string | - | Files changed within duration ("1h", "2d", "3.commits") | | pathPattern | string | - | Filter by path substring | | fresh | boolean | false | Check index freshness before searching |

SearchResult:

| Field | Type | Description | |-------|------|-------------| | file | string | File path relative to root | | lineNumber | number | Line number (1-based) | | line | string | The matching line content |

xg.indexStatus(): string

Get the current index status.

xg.root: string (getter)

Get the root directory path.

xg.indexPath: string (getter)

Get the index file path.

How It Works

xgrep builds a trigram inverted index of your codebase. On the first search, the index is built automatically. Subsequent searches use the index to narrow down candidate files before scanning, making repeated searches extremely fast.

| Benchmark | xgrep | ripgrep | Speedup | |-----------|-------|---------|---------| | Linux kernel (92K files) | 38ms | 2,236ms | 59x | | ripgrep source (248 files) | 2.5ms | 7.9ms | 3.1x |

CLI

xgrep also provides a CLI tool. Install via Rust:

cargo install xgrep-search
xg "pattern" --type rs

License

MIT