# renames

> cli-renames

Latest version **1.0.3** (published 2022-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install renames
pnpm add renames
yarn add renames
bun add renames
```

Provides the command `renames`.

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-07-20 |
| First published | 2022-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 81 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | peterroe |
| Maintainers | peterroe |
| Keywords | cli, typescript, renames |

## Links

- npm: https://www.npmjs.com/package/renames
- npm.io page: https://npm.io/package/renames

## Dependencies (2)

- [chalk](https://npm.io/package/chalk.md) ^5.0.1
- [debug](https://npm.io/package/debug.md) ^4.3.4

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2022-07-20
- 1.0.2 — 2022-07-19
- 1.0.1 — 2022-07-09
- 1.0.0 — 2022-07-09

## README

![img](./logo.svg)

## renames

A good helper for batch renaming files.

## Install

```sh
$ npm i -g renames
```

## Usage 

```shell
$ 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:

```shell
├─ 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.


```shell
renames "([A-Z])([a-z]*)([A-Z])([a-z]*).tsx" "([a-z])([a-z]*)-([a-z])([a-z]*).tsx" --dir ./components --write
```

```shell
├─ components
│  ├─ list-post.tsx
│  ├─ nav-bar.tsx
│  ├─ toggle-theme.tsx
```

**example 2:**

```shell
├─ tests
│  ├─ sort_test.js
│  ├─ match_test.js
│  ├─ index_test.js
```

```shell
renames "([a-z]*)_([a-z]*).js" "([a-z]*).([a-z]*).ts" --dir ./tests --write
```

```shell
├─ tests
│  ├─ sort.test.ts
│  ├─ match.test.ts
│  ├─ index.test.ts
```

**example 3:**

```shell
├─ src
│  ├─ qBar.js
│  ├─ BFoo.js
│  ├─ zBaz.js
```

```shell
'([qB]+)([A-Z])([a-z]*).js' '()([A-Z])([a-z]*).js' --dir src --write
```

```shell
├─ 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:

```shell 
├─ src
│  ├─ sLog.ts
│  ├─ qWitch.ts
│  ├─ Index.ts
│  ├─ App.ts
```

Transform to:

```shell
├─ src
│  ├─ Log.ts
│  ├─ Witch.ts
│  ├─ Index.ts
│  ├─ App.ts
```

You should run:

```diff
- 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 // ✅
```

---
_Source: https://npm.io/package/renames · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
