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

replacing

v2.0.1

Published

This is a super lightweight CLI for searching and replacing file contents with ECMAScript regex.

Downloads

12

Readme

Replacing

This is a super lightweight CLI for searching and replacing file contents with ECMAScript regex.

replacing does as little in the way of custom logic as possible. In fact, it does not even search and replace linewise, it simply calls replaceAll on the entire input text and prints the linewise diff.

Installation

npm i -g replacing

Requires bun:

curl -fsSL https://bun.sh/install | bash

replacing expects lines of files piped through stdin. A great candidate for this is fd. The rest of this readme will assume the following shell alias:

alias r='fd|replacing'

Usage

r [PATTERN [REPLACEMENT [MODIFY]]]

The argument parsing for rp is positional and depends on the number of arguments provided:

  1. Simply print the sorted file paths passed through stdin.

  2. Print lines with text matching the specified regex pattern. Default flags are gm, plus i if the pattern is all lowercase (smartcase). To specify custom flags, end your pattern with \/flags. Ending your pattern with \/ indicates no flags.

  3. Print with replacements. Ampersands (&) in the replacement string will be substituted with the corresponding match. Literal ampersands can be specified with \&.

  4. Modify the input files accordingly with -m. You must be in a clean working git directory.

    If you want to forcibly modify the input files regardless of git status, specify -mf.

Examples

Print the piped file paths:

r

Print lines matching pattern config:

r config

Print lines replacing matched pattern config with text store.config:

r config store.config

Substitute back in the matching string with &. This has the same result as the above example:

r config 'store.&'

Modify files, replacing matched pattern config with text store.config if git status is clean:

r config 'store.&' -m

Forcibly modify regardless of git status:

r config 'store.&' -mf

Lookarounds and word boundaries work. Print lines matching the word config not after store., replacing with store.config:

r '(?<!store\.)\bconfig\b' 'store.&'

Tips

Clearing Scrollback

You might consider aliasing fd or whatever file-listing program you're using to clear the scrollback first:

alias fd="printf '\33c\e[3J' && fd"

Excluding Files

You can use all of the features of the piping program to narrow down your search. For example, to exclude any file beginning with store:

fd -E 'store*' | replacing

Git Working Directory Usage

You might find it cumbersome to commit any changes before making modifications. One option is to make a commit before running replacing, then after making modifications, you can just shove unstaged changes into the previous commit:

alias gfixup='git commit -a --amend --no-edit'