{"id":17448308,"url":"https://github.com/mesqueeb/replace-regex","last_synced_at":"2025-04-30T17:44:40.067Z","repository":{"id":243175303,"uuid":"811672015","full_name":"mesqueeb/replace-regex","owner":"mesqueeb","description":"📂 TS compatible modern nodeJS find-and-replace in files with Regex \u0026 Glob support","archived":false,"fork":false,"pushed_at":"2025-02-19T18:54:13.000Z","size":371,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-23T16:57:27.304Z","etag":null,"topics":["file-text-replacer","find-and-replace","glob-find-and-replace","glob-replace-text","regex-replacer","replace-in-files","replace-text-in-files"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/mesqueeb.png","metadata":{"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},"funding":{"github":"mesqueeb","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2024-06-07T04:24:25.000Z","updated_at":"2025-02-19T18:54:17.000Z","dependencies_parsed_at":"2024-06-07T06:30:25.205Z","dependency_job_id":"76ce3aa9-668e-4e5a-8ab6-72b987150bd1","html_url":"https://github.com/mesqueeb/replace-regex","commit_stats":null,"previous_names":["mesqueeb/replace-regex"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Freplace-regex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Freplace-regex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Freplace-regex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Freplace-regex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mesqueeb","download_url":"https://codeload.github.com/mesqueeb/replace-regex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251753783,"owners_count":21638379,"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":["file-text-replacer","find-and-replace","glob-find-and-replace","glob-replace-text","regex-replacer","replace-in-files","replace-text-in-files"],"created_at":"2024-10-17T20:06:57.652Z","updated_at":"2025-04-30T17:44:40.016Z","avatar_url":"https://github.com/mesqueeb.png","language":"TypeScript","funding_links":["https://github.com/sponsors/mesqueeb"],"categories":[],"sub_categories":[],"readme":"# replace-regex 📂\n\n\u003ca href=\"https://www.npmjs.com/package/replace-regex\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/replace-regex.svg\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/replace-regex\"\u003e\u003cimg src=\"https://img.shields.io/npm/dw/replace-regex.svg\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\n📂 TS compatible modern nodeJS find-and-replace in files with Regex \u0026 Glob support.\n\n```\nnpm i replace-regex\n```\n\n## Features\n\n- **Glob Support**: Use glob patterns to specify files.\n- **Regex Support**: Replace text using regular expressions.\n- **Dry Run**: Preview changes without modifying files.\n- **Count**: Count matches and replacements.\n- **Customizable**: Pass custom options to fine-tune behavior.\n\n## Usage\n\n### Basic Usage\n\n```ts\nimport { replaceRegex } from 'replace-regex'\n\nconst results = await replaceRegex({\n  files: 'src/**/*.js',\n  from: /foo/g,\n  to: 'bar',\n  dry: false,\n})\n\nconsole.log(results)\n```\n\n### CLI Usage\n\nYou can use the `replace-regex` CLI to find and replace text in files using regular expressions right from the terminal.\n\n```sh\nUsage\n  $ replace-regex \u003cfiles…\u003e\n\nOptions\n  --from            Regex pattern or string to find (Can be set multiple times)\n  --to              Replacement string or function (Required)\n  --dry             Dry run (do not actually replace, just show what would be replaced)\n  --no-glob         Disable globbing\n  --ignore          Ignore files matching this pattern (Can be set multiple times)\n  --ignore-case     Search case-insensitively\n\nExamples\n  $ replace-regex --from='fox' --to='🦊' foo.md\n  $ replace-regex --from='v\\\\d+\\\\.\\\\d+\\\\.\\\\d+' --to='v$npm_package_version' foo.css\n  $ replace-regex --from='blob' --to='blog' 'some/**/[gb]lob/*' '!some/glob/foo'\n```\n\n### Options\n\n- `files` (string or string[]): Glob patterns or file paths to process.\n- `from` (string | RegExp | (file: string) =\u003e string | RegExp): The pattern to search for.\n- `to` (string | (match: string, file: string) =\u003e string): The replacement string or function.\n- `dry` (boolean, optional): If true, no files will be overwritten. Default is `false`.\n- `ignore` (string[], optional): An array of glob patterns to exclude matches.\n- `disableGlobs` (boolean, optional): If true, disables glob pattern matching. Default is `false`.\n- `fastGlobOptions` (object, optional): Options to pass to fast-glob.\n\n### CLI Examples\n\nTo replace all occurrences of the word `fox` with `🦊` in the file `foo.md`:\n\n```sh\nreplace-regex --from='fox' --to='🦊' foo.md\n```\n\nTo replace version numbers in a CSS file with the version from your `package.json`:\n\n```sh\nreplace-regex --from='v\\\\d+\\\\.\\\\d+\\\\.\\\\d+' --to='v$npm_package_version' foo.css\n```\n\nTo replace the word `blob` with `blog` in files matching a glob pattern, while ignoring certain files:\n\n```sh\nreplace-regex --from='blob' --to='blog' 'some/**/[gb]lob/*' '!some/glob/foo'\n```\n\nTo perform a dry run (no files will be overwritten):\n\n```sh\nreplace-regex --from='fox' --to='🦊' --dry foo.md\n```\n\nTo perform a case-insensitive search and replace:\n\n```sh\nreplace-regex --from='fox' --to='🦊' --ignore-case foo.md\n```\n\n### API Examples\n\n**Replace text in JavaScript files**\n\n```ts\nreplaceRegex({\n  files: 'src/**/*.js',\n  from: /console\\.log/g,\n  to: 'logger.log',\n  dry: false,\n})\n```\n\n**Dry Run**\n\n```ts\nconst result = await replaceRegex({\n  files: 'src/**/*.js',\n  from: /foo/g,\n  to: 'bar',\n  dry: true, // No files will be overwritten\n})\n\nconsole.log(`result → `, result)\n```\n\n**Custom Replacement Function**\n\n```ts\nreplaceRegex({\n  files: 'src/**/*.js',\n  from: /foo/g,\n  to: (match, file) =\u003e `${match.toUpperCase()} in ${file}`,\n  dry: false,\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesqueeb%2Freplace-regex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmesqueeb%2Freplace-regex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesqueeb%2Freplace-regex/lists"}