A CLI tool to replace names in a folder, including file/directory names and file contents
npm install change-nameA CLI tool to replace names in a folder, including file/directory names and file contents.
- Recursively renames files and directories
- Replaces names in text file contents
- Supports multiple case transformations:
- camelCase
- constantCase
- headerCase
- noCase
- paramCase
- pascalCase
- pathCase
- sentenceCase
- snakeCase
- capitalCase
- dotCase
- Safety checks with .name file
- Interactive mode with --ask flag
- Validates that rename operations are idempotent
``bash`
npm install -g change-nameor
pnpm add -g change-name
`bash`
change-name
The to parameter defaults to the current directory name.
By default, change-name requires a .name file to exist in the directory. This prevents accidental name changes. The .name file is automatically deleted after a successful rename operation if the changes are verified to be idempotent.
- -a, --ask - Prompt user to provide a new name or confirm the default choice--unsafe
- - Skip the .name file check and change the name in all circumstances--only-once
- - Delete the .name file in every case, even if no issues found
`bashChange name from "myapp" to "yourapp"
change-name myapp yourapp
$3
This tool is particularly useful when:
- Forking or cloning a project template
- Renaming a project after initialization
- Bulk renaming identifiers across a codebase
- Standardizing naming conventions
How It Works
1. File Discovery: Recursively scans all files and directories (excluding
.git and node_modules)
2. Name Transformation: Applies all case transformations to both file/directory names and file contents
3. Safety Validation: Performs a second pass to ensure all transformations are idempotent (i.e., running again produces no changes)
4. Cleanup: Deletes the .name file if all transformations are verifiedSafety Checks
The tool performs safety checks to prevent destructive operations:
1. Requires a
.name file (unless --unsafe is used)
2. Validates that rename operations are idempotent
3. Skips binary files to prevent corruption
4. Validates that new names match the pattern [0-9a-z\-_]`MIT