change-name
v0.3.2
Published
A CLI tool to replace names in a folder, including file/directory names and file contents
Maintainers
Readme
change-name
A CLI tool to replace names in a folder, including file/directory names and file contents.
Features
- 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
.namefile - Interactive mode with
--askflag - Validates that rename operations are idempotent
Installation
npm install -g change-name
# or
pnpm add -g change-nameUsage
Basic Usage
change-name <from> [to]The to parameter defaults to the current directory name.
Safety Mechanism
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.
Options
-a, --ask- Prompt user to provide a new name or confirm the default choice--unsafe- Skip the.namefile check and change the name in all circumstances--only-once- Delete the.namefile in every case, even if no issues found
Examples
# Change name from "myapp" to "yourapp"
change-name myapp yourapp
# Interactive mode - prompt for the new name
change-name myapp --ask
# Skip safety check (not recommended for production)
change-name myapp newname --unsafe
# Delete .name file even if issues found
change-name myapp newname --only-onceUse Case
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
- File Discovery: Recursively scans all files and directories (excluding
.gitandnode_modules) - Name Transformation: Applies all case transformations to both file/directory names and file contents
- Safety Validation: Performs a second pass to ensure all transformations are idempotent (i.e., running again produces no changes)
- Cleanup: Deletes the
.namefile if all transformations are verified
Safety Checks
The tool performs safety checks to prevent destructive operations:
- Requires a
.namefile (unless--unsafeis used) - Validates that rename operations are idempotent
- Skips binary files to prevent corruption
- Validates that new names match the pattern
[0-9a-z\-_]
License
MIT
