1.0.3 • Published 2 years ago
renames v1.0.3
renames
A good helper for batch renaming files.
Install
$ npm i -g renames
Usage
$ renames <beforePatten> <afterPatten> --dir <dir> # preview
$ renames <beforePatten> <afterPatten> --dir <dir> --write # write to disk
example 1:
Suppose you now have the following directory structure:
├─ components
│ ├─ ListPost.tsx
│ ├─ NavBar.tsx
│ ├─ ToggleTheme.tsx
Just run renames
and it will rename all files in the directory to match the new file name.
renames "([A-Z])([a-z]*)([A-Z])([a-z]*).tsx" "([a-z])([a-z]*)-([a-z])([a-z]*).tsx" --dir ./components --write
├─ components
│ ├─ list-post.tsx
│ ├─ nav-bar.tsx
│ ├─ toggle-theme.tsx
example 2:
├─ tests
│ ├─ sort_test.js
│ ├─ match_test.js
│ ├─ index_test.js
renames "([a-z]*)_([a-z]*).js" "([a-z]*).([a-z]*).ts" --dir ./tests --write
├─ tests
│ ├─ sort.test.ts
│ ├─ match.test.ts
│ ├─ index.test.ts
example 3:
├─ src
│ ├─ qBar.js
│ ├─ BFoo.js
│ ├─ zBaz.js
'([qB]+)([A-Z])([a-z]*).js' '()([A-Z])([a-z]*).js' --dir src --write
├─ src
│ ├─ ar.js
│ ├─ Foo.js
│ ├─ zBaz.js
Base patten rule
patten | description |
---|---|
() | match an expression |
[a-z] | match a lowercase letter |
[A-Z] | match an uppercase letter |
* | match any number of characters |
? | match zero or one character |
+ | match one or more characters |
Notice
In the <beforePatten>
and <afterPatten>
, the number of ()
must be equal.
Such as if you want:
├─ src
│ ├─ sLog.ts
│ ├─ qWitch.ts
│ ├─ Index.ts
│ ├─ App.ts
Transform to:
├─ src
│ ├─ Log.ts
│ ├─ Witch.ts
│ ├─ Index.ts
│ ├─ App.ts
You should run:
- renames '([a-z]?)([A-Z])([a-z]*).js' '([A-Z])([a-z]*).js --dir ./src --write // ❌
+ renames '([a-z]?)([A-Z])([a-z]*).js' '()([A-Z])([a-z]*).js' --dir ./src --write // ✅