{"id":15681691,"url":"https://github.com/jonschlinkert/replace-case","last_synced_at":"2025-05-07T12:43:01.214Z","repository":{"id":57353686,"uuid":"340321700","full_name":"jonschlinkert/replace-case","owner":"jonschlinkert","description":"Like String.prototype.replace() but attempts to match the casing of the substring being replaced. Useful when renaming mixed-case variables, refactoring code or moving hard-coded values into variables. ","archived":false,"fork":false,"pushed_at":"2023-11-04T02:19:17.000Z","size":13,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-28T20:47:00.369Z","etag":null,"topics":["case","case-sensitive","match","regex","regexp","replace","replacement","string"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":null,"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":"jonschlinkert"}},"created_at":"2021-02-19T09:35:34.000Z","updated_at":"2023-11-04T02:19:15.000Z","dependencies_parsed_at":"2025-03-11T03:41:28.973Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/replace-case","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Freplace-case","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Freplace-case/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Freplace-case/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Freplace-case/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/replace-case/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252880094,"owners_count":21818933,"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":["case","case-sensitive","match","regex","regexp","replace","replacement","string"],"created_at":"2024-10-03T16:58:40.539Z","updated_at":"2025-05-07T12:43:01.187Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","funding_links":["https://github.com/sponsors/jonschlinkert"],"categories":[],"sub_categories":[],"readme":"# replace-case [![NPM version](https://img.shields.io/npm/v/replace-case.svg?style=flat)](https://www.npmjs.com/package/replace-case) [![NPM monthly downloads](https://img.shields.io/npm/dm/replace-case.svg?style=flat)](https://npmjs.org/package/replace-case) [![NPM total downloads](https://img.shields.io/npm/dt/replace-case.svg?style=flat)](https://npmjs.org/package/replace-case) [![Tests](https://github.com/jonschlinkert/replace-case/actions/workflows/test.yml/badge.svg)](https://github.com/jonschlinkert/replace-case/actions/workflows/test.yml)\n\n\u003e Like String.prototype.replace() but attempts to match the casing of the substring being replaced.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save replace-case\n```\n\n## Usage\n\n```js\nconst replace = require('replace-case');\nconst input = 'foo Foo FOO foo';\n\n// Uses \"gi\" RegExp flags by default\nconsole.log(replace(input, 'foo', 'bar')); //=\u003e bar Bar BAR bar\nconsole.log(replace(input, '[fF]oo', 'bar', 'g')); //=\u003e bar Bar FOO bar\nconsole.log(replace(input, 'foo', 'bar', 'i')); //=\u003e bar Foo FOO foo\nconsole.log(replace(input, 'foo', 'bar', '')); //=\u003e bar Foo FOO foo\n```\n\n**Signature**\n\n```js\nreplace(input, substring, replacement[, flags]);\n```\n\n**Params**\n\n* `input` (String) The string to modify\n* `substring` (String) The \"old\" string to replace\n* `replacement` (String) The \"new\" string to use as a replacement.\n* `flags` (String) Optional [RegExp flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Advanced_searching_with_flags_2) to use. By default, `gi` is used.\n\n## Usage Examples\n\n```js\nconst input = `\n  .alphaconfig.json\n  AlphaWord\n  Alpha\n  ALPHA_FOO_BAR\n`;\n\n// Replace all occurrences of \"alpha\" with \"beta\"\nconsole.log(replace(input, 'alpha', 'beta'));\n// Replace only the first occurrence of \"alpha\" with \"beta\"\nconsole.log(replace(input, 'alpha', 'beta', 'i'));\n// Replace only when surrounded by word boundaries (capture group is unecessary and is only for clarity)\nconsole.log(replace(input, '\\\\b(?:alpha)\\\\b', 'beta'));\n// Replace all occurrences of \"alpha\" (optionally followed by \"config\") with \"beta\"\nconsole.log(replace(input, 'alpha(config)*', 'beta'));\n// Replace all occurrences of \"alpha\" (optionally followed by zero or more characters that are\n// not a space, underscore, or dot)\nconsole.log(replace(input, 'alpha([^\\\\s_.]*)', 'beta'));\n```\n\nResults in the following:\n\n```\n  .betaconfig.json\n  BetaWord\n  Beta\n  BETA_FOO_BAR\n\n  .betaconfig.json\n  AlphaWord\n  Alpha\n  ALPHA_FOO_BAR\n\n  .alphaconfig.json\n  AlphaWord\n  Beta\n  ALPHA_FOO_BAR\n\n  .beta.json\n  BetaWord\n  Beta\n  BETA_FOO_BAR\n\n  .beta.json\n  beta\n  Beta\n  BETA_FOO_BAR\n```\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\nPlease read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2023, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the MIT License.\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 03, 2023._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Freplace-case","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Freplace-case","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Freplace-case/lists"}