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

rexreplace

v7.1.11

Published

Search & replace across files with a CLI tool that makes you trust what you are doing.

Downloads

18,605

Readme

RexReplace

CI-test NPM downloads npm version FOSSA Status OPEN open source software

RexReplace is a versatile tool to search and replace text in files from the command line. It's inspired by how developers often need to do quick fixes or one-liners for build scripts.

Key features:

  • Easy and intuitive notation makes you trust what you are doing
  • Replacement can be javascript code - giving you Turing complete flexibility
  • Pinpoint the exact files with glob notation (docs/*.md represents each markdown file in docs/)
  • No more brute-forcing the right combination of find, cat, sed, tr, and awk to replace a text pattern in the right files

Install

To use RexReplace from your command line

> npm install -g rexreplace

To use RexReplace from an npm build script:

> yarn add rexreplace --dev
# or
> npm install rexreplace --save-dev

Examples

Let 'foobar' become 'xxxbar' in myfile.md

> rexreplace 'Foo' 'xxx' myfile.md

Hard for your fingers to write on your keyboard? We got you covered with the rr alias for rexreplace

> rr Foo xxx myfile.md

Catch the beginning

Let all markdown files in the docs/ dir get headlines moved one level deeper

> rexreplace '^#' '##' docs/*.md

Using glob notation to pinpoint files

Fix a spell error in all javascript and typescript files in the folders src/ and test/ recursively.

> rexreplace 'foubar' 'foobar' '{src,test}/**/*.{js,ts}'

Dynamically generated content

Let the version number from package.json get into your distribution js files (use the string VERSION in your source files).

> rexreplace 'VERSION' 'require("./package.json").version' -j dist/*.js

Require have been given the alias r and both are expanded to understand relative paths even without ./ prepended. As the file extension is not needed eighter you will get the same result writing:

> rexreplace 'VERSION' 'r("package").version' -j dist/*.js

Reference a matching group

Let 'foobar' become 'barfoo' in myfile.md

> rexreplace '(foo)(.*)' '$2$1' myfile.md

RexReplace defaults to treating as an alias for $ so the following will do the same as the previous example

> rexreplace '(foo)(.*)' '€2€1' myfile.md

Surviving backslash-escape hell

Let foo[bar] become foo.0.[bar] in myfile.md

> rexreplace '\[' '.0.[' myfile.md

The [ as a literate char must be escaped according to regex. If you run the command as a parameter (this could be from a script in package.json) you need to escape the escape:

"scripts":{
  "fix": "rexreplace '\\[' '.0.[' myfile.md"
}

RexReplace defaults to treating § as an alias for \ so the following give same result:

> rexreplace '§[' '.0.[' myfile.md
"scripts":{
  "fix": "rexreplace '§[' '.0.[' myfile.md"
}

More relevant examples

Per file info

Add creation time, name of the file and human readable file size as the first line in each file in test-run recursively.

> rexreplace '^' 'ctime_ + name_ + size + nl' -j -M 'dist/**/*.*'

Matching pairs

Let both "foo 'is' bar" and ' foo "was" bar' ' become » foo ... bar « independent of using ' or "

> rexreplace '(['"])([^\1]+)\1' '» $2 «' myfile.md

Usage

> rexreplace pattern replacement [fileGlob|option]+

| Flag | Effect | | ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -v | --version Print rexreplace version (can be given as only argument) [boolean] | | -V | --verbose More chatty output [boolean] | | -L | --literal Literal string search (no regex used when searching) [boolean] | | -I | --void-ignore-case Void case insensitive search pattern. [boolean] | | -G | --void-global Void global search (stop looking after the first match). [boolean] | | -s | --dot-all Have . also match newline. [boolean] | | -M | --void-multiline Void multiline search pattern. Makes ^ and $ match start/end of whole content rather than each line. [boolean] | | -u | --unicode Treat pattern as a sequence of unicode code points. [boolean] | | -e | --encoding Encoding of files/piped data. [default: "utf8"] | | -E | --engine What regex engine to use: [choices: "V8"] [default: "V8"] | | -q | --quiet Only display errors (no other info) [boolean] | | -Q | --quiet-total Never display errors or info [boolean] | | -H | --halt Halt on first error [boolean] [default: false] | | -d | --debug Print debug info [boolean] | | -€ | --void-euro Void having as alias for $ in pattern and replacement parameters [boolean] | | | --void-section Void having § as alias for \ in pattern and replacement parameters [boolean] | | -o | --output Output the final result instead of saving to file. Will also output content even if no replacement has taken place. [boolean] | | -A | --void-async Handle files in a synchronous flow. Good to limit memory usage when handling large files. [boolean] | | -B | --void-backup Avoid temporary backing up file. Works async (independent of -A flag) and will speed up things but at one point data lives only in memory, and you will lose the content if the process is abrupted. [boolean] | | -b | --keep-backup Keep a backup file of the original content. [boolean] | | -m | --output-match Output each match on a new line. Will not replace any content but you still need to provide a dummy value (like _) as replacement parameter. If search pattern does not contain matching groups the full match will be outputted. If search pattern does contain matching groups only matching groups will be outputted (same line with no delimiter). [boolean] | | -T | --trim-pipe Trim piped data before processing. If piped data only consists of chars that can be trimmed (new line, space, tabs...) it will become an empty string. [boolean]