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

regname

v1.0.4

Published

A CLI tool to perform regex-based file renaming in the current directory.

Downloads

48

Readme

regname

一个简单的 Node.js CLI 工具,通过正则表达式对当前目录下的文件进行重命名。

安装

npm install -g regname

使用方法

默认情况下(不带 -y 参数)为 模拟执行(dry-run) 模式,它会输出匹配到的文件及重命名结果,但不会真正修改文件名:

regname "^匹配正则(.*)\\.ext$" '替换结果$1.ext'

如果你确认模拟结果无误,加上 -y 参数即可实际重命名文件:

regname -y "^匹配正则(.*)\\.ext$" '替换结果$1.ext'

排除特定文件

你可以使用 -n 参数传入一个正则表达式,用于排除不希望被重命名的文件。 例如,你想重命名所有文件,但想跳过 .pdf 文件:

regname -n "\.pdf$" "(.*)" "prefix-#1"

示例

假设当前目录下有以下文件:

  • test-1.txt
  • test-2.txt

运行:

regname "^test-(.*)\\.txt$" 'prod-$1.txt'

⚠️ 终端解析陷阱注意: 在终端(特别是 Bash/Zsh)中,如果替换字符串中包含 $ 符号并使用双引号,终端会把 $1 提前解析为空的环境变量,导致结果错误!

为了解决这个问题,你有两种选择

  1. 使用单引号:如上例所示,将替换字符串用 ' 包围 'prod-$1.txt'
  2. 使用 # 替代 $(推荐):由于 # 不会被 shell 提前解析,本工具内置支持使用 #1#2 代替 $1$2,你可以安心使用双引号:
regname "^test-(.*)\\.txt$" "prod-#1.txt"

输出:

test-1.txt -> prod-1.txt
test-2.txt -> prod-2.txt


提示: 当前为模拟执行模式,并未实际重命名。如果确认无误,请加上 -y 参数执行。

确认无误后,运行:

regname -y "^test-(.*)\\.txt$" 'prod-$1.txt'

输出:

[成功] test-1.txt -> prod-1.txt
[成功] test-2.txt -> prod-2.txt