{"id":13582843,"url":"https://github.com/sindresorhus/replace-in-files-cli","last_synced_at":"2025-10-27T22:18:37.972Z","repository":{"id":45072195,"uuid":"191551522","full_name":"sindresorhus/replace-in-files-cli","owner":"sindresorhus","description":"Replace matching strings and regexes in files","archived":false,"fork":false,"pushed_at":"2024-06-26T12:00:47.000Z","size":23,"stargazers_count":175,"open_issues_count":4,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T19:26:15.441Z","etag":null,"topics":["cli-app","command-line-tool","nodejs","npm-package","replace","replace-in-files","replace-text","search-and-replace"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-12T10:42:59.000Z","updated_at":"2024-06-26T12:00:51.000Z","dependencies_parsed_at":"2024-11-06T00:33:06.509Z","dependency_job_id":"177002fc-d00d-4489-a756-4d3a5bace0d2","html_url":"https://github.com/sindresorhus/replace-in-files-cli","commit_stats":{"total_commits":21,"total_committers":6,"mean_commits":3.5,"dds":"0.23809523809523814","last_synced_commit":"b6e9b0d4d10ae50a4894ae3bfe0af6c30acf8000"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Freplace-in-files-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Freplace-in-files-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Freplace-in-files-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Freplace-in-files-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/replace-in-files-cli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246575005,"owners_count":20799252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli-app","command-line-tool","nodejs","npm-package","replace","replace-in-files","replace-text","search-and-replace"],"created_at":"2024-08-01T15:03:04.113Z","updated_at":"2025-10-27T22:18:37.967Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["JavaScript","nodejs"],"sub_categories":[],"readme":"# replace-in-files-cli\n\n\u003e Replace matching strings and regexes in files\n\n## Install\n\n```sh\nnpm install --global replace-in-files-cli\n```\n\n## Usage\n\n```\n$ replace-in-files --help\n\n  Usage\n    $ replace-in-files \u003cfiles…\u003e\n\n  Options\n    --regex           Regex pattern to find  (Can be set multiple times)\n    --string          String to find  (Can be set multiple times)\n    --replacement     Replacement string  (Required)\n    --ignore-case     Search case-insensitively\n    --no-glob         Disable globbing\n    --dry-run         Show what would be replaced without making changes\n\n  Examples\n    $ replace-in-files --string='horse' --regex='unicorn|rainbow' --replacement='🦄' foo.md\n    $ replace-in-files --regex='v\\d+\\.\\d+\\.\\d+' --replacement=v$npm_package_version foo.css\n    $ replace-in-files --string='blob' --replacement='blog' 'some/**/[gb]lob/*' '!some/glob/foo'\n    $ replace-in-files --dry-run --string='old' --replacement='new' file.txt\n\n  You can use the same replacement patterns as with `String#replace()`, like `$\u0026`.\n\n  When working with quotes in shell commands, escape them with backslashes:\n    $ replace-in-files --string='\\\"use strict\\\";' --replacement='\\\"use strict\\\";\\nrequire(\\\"module\\\");' file.js\n```\n\nReal-world use-case: [Bumping version number in a file when publishing to npm](https://github.com/sindresorhus/modern-normalize/commit/c1d65e3f7daba2b695ccf837d2aef19d586d1ca6)\n\nThe regex should be [JavaScript flavor](https://www.regular-expressions.info/javascript.html).\n\n## API\n\nYou can also use this package programmatically:\n\n```js\nimport replaceInFiles from 'replace-in-files-cli';\n\n// Find and replace\nawait replaceInFiles('*.js', {\n\tfind: ['old', /version \\d+/],\n\treplacement: 'new'\n});\n\n// Transform entire file content\nawait replaceInFiles('*.js', {\n\ttransform: (content, filePath) =\u003e `/* Banner */\\n${content}`\n});\n\n// Combine find/replace with transform (transform runs after find/replace)\nawait replaceInFiles('*.js', {\n\tfind: ['old'],\n\treplacement: 'new', \n\ttransform: (content, filePath) =\u003e `/* ${filePath} */\\n${content}`\n});\n```\n\nThe `transform` option provides full control over file content:\n- **Standalone**: Use alone for prepend, append, or complex transformations\n- **Combined**: Use with `find`/`replacement` - transform runs after find/replace operations\n- **Parameters**: Receives `(content, filePath)` for context-aware transformations\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Freplace-in-files-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Freplace-in-files-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Freplace-in-files-cli/lists"}