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

glob-replace

v0.0.2

Published

Replace patterns across file globs - a thin wrapper around JavaScript's string.replace(RegExp(...), replacement)

Downloads

313

Readme

glob-replace

Replace patterns across file globs - a thin wrapper around JavaScript's string.replace(RegExp(...), replacement).

Usage

npx glob-replace \
  --glob <glob> \
  --find <pattern> \
  --replace <replacement>

Examples

# Simple replacement
npx glob-replace \
  --glob 'src/**/*.ts' \
  --find 'foo' \
  --replace 'bar'

# Global replace with backreferences
npx glob-replace \
  --glob 'src/**/*.ts' \
  --find '(\w+)_(\w+)' \
  --replace '$1-$2' \
  --flags g

# Multiple globs
npx glob-replace \
  --glob 'src/**/*.js' \
  --glob 'lib/**/*.js' \
  --find 'old' \
  --replace 'new'

# From stdin
echo 'hello_world' | npx glob-replace \
  --find '(\w+)_(\w+)' \
  --replace '$1-$2' \
  --stdin

# Dry run (preview changes)
npx glob-replace \
  --glob '**/*.md' \
  --find 'old' \
  --replace 'new' \
  --dry-run

Options

| Option | Description | | ---------------------- | --------------------------------------- | | -g, --glob <g> | File glob to process (repeatable) | | -f, --find <pattern> | Pattern to search for | | -r, --replace <str> | Replacement string | | --flags <f> | RegExp flags (e.g., g, gi) | | --literal | Treat pattern as literal string | | --stdin | Read from stdin, write to stdout | | --dry-run | Preview without writing | | --encoding <e> | File encoding (default: utf8) | | --concurrency <n> | Max parallel files (default: CPU count) |

Notes

  • Uses JavaScript RegExp + String.prototype.replace
  • Backreferences use $1, $2, etc.
  • No flags by default—add --flags g for global replacement
  • At least one --glob is required unless --stdin is used

Shell quoting patterns

Patterns are passed directly to JavaScript RegExp. Most escaping issues come from the shell, not glob-replace.

Single quotes — use by default:

npx glob-replace \
  --glob '**/*.txt' \
  --find '\bword\b' \
  --replace 'replacement'

Concatenated quotes — when you need shell expansion:

name="user"
npx glob-replace \
  --glob '**/*.conf' \
  --find '^'"$name"'\s*=' \
  --replace 'found='

Here-docs — when patterns contain quotes or span multiple lines:

npx glob-replace \
  --glob 'src/**/*.js' \
  --find "$(cat <<'FIND'
const\s+(\w+)\s*=\s*'([^']+)'
FIND
)" \
  --replace "$(cat <<'REPLACE'
let $1 = '$2'
REPLACE
)"

Here-docs are especially useful when matching JavaScript source, where single quotes in patterns conflict with shell quoting.