{"id":16000450,"url":"https://github.com/jedwards1211/preserve-case","last_synced_at":"2025-09-28T13:30:49.781Z","repository":{"id":57329918,"uuid":"94554078","full_name":"jedwards1211/preserve-case","owner":"jedwards1211","description":"very comprehensive case-preserving string.replace","archived":false,"fork":false,"pushed_at":"2018-08-13T17:09:33.000Z","size":160,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-12T02:02:26.252Z","etag":null,"topics":["case-preserving","preserve-case","refactoring","replace","replace-text","string-manipulation","string-replace","string-substitution"],"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/jedwards1211.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-16T14:54:18.000Z","updated_at":"2023-04-04T18:57:25.000Z","dependencies_parsed_at":"2022-08-29T04:30:18.829Z","dependency_job_id":null,"html_url":"https://github.com/jedwards1211/preserve-case","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fpreserve-case","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fpreserve-case/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fpreserve-case/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fpreserve-case/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jedwards1211","download_url":"https://codeload.github.com/jedwards1211/preserve-case/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234518878,"owners_count":18845842,"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-preserving","preserve-case","refactoring","replace","replace-text","string-manipulation","string-replace","string-substitution"],"created_at":"2024-10-08T09:03:56.474Z","updated_at":"2025-09-28T13:30:44.523Z","avatar_url":"https://github.com/jedwards1211.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# preserve-case\n\n[![Build Status](https://travis-ci.org/jedwards1211/preserve-case.svg?branch=master)](https://travis-ci.org/jedwards1211/preserve-case)\n[![Coverage Status](https://codecov.io/gh/jedwards1211/preserve-case/branch/master/graph/badge.svg)](https://codecov.io/gh/jedwards1211/preserve-case)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n\ncase-preserving `string.replace`\n\n## Usage\n\n```\nnpm install --save preserve-case\n```\n\n```js\nimport replace from 'preserve-case'\n\nconsole.log(replace.all('foo bar FOO_BAR foo-bar fooBar foo-Bar', 'foo bar', 'baz qux'))\n// baz qux BAZ_QUX baz-qux bazQux baz-Qux\n```\n\n## API\n\n### `replace(str, query, replacement, [options])`\n\n```js\nreplace(\n  str: string,\n  query: string | RegExp,\n  replacement: string | Function,\n  options?: {\n    caseTypes?: Array\u003cstring\u003e\n  }\n): string`\n```\n\nWorks exactly like `str.replace(query, replacement)`, except that:\n* it preserves the case of what it replaces (using the marvelous `case` package)\n* if `query` is a string, it matches `query` in any case.  (Under the hood, it creates and uses\n  a `RegExp` with all `caseTypes` of `query` joined together, e.g.\n  `str.replace(/foo bar|FOO BAR|fooBar|FooBar|.../, ...)`)\n\n`options.caseTypes` defaults to all types built into the [`case`](https://github.com/nbubna/Case) package.\nThis may be more than you want, so look into it.  For instance, the other cases of 'foo bar' include, but may not be\nlimited to:\n\n```\n'Foo Bar'\n'Foo bar'\n'FOO BAR'\n'fooBar'\n'FooBar'\n'foo-bar'\n'Foo-Bar'\n'foo_bar'\n'FOO_BAR'\n```\n\n### `replace.all(str, query, replacement, [options])`\n\nUnlike `replace`, this replaces *all* occurrences of `query`, not just the first one, even if `query` is a `string` or\na `RegExp` without the `g` (global) flag.\n\n## Acknowledgements\n\nThanks to Nathan Bubna for his [`case`](https://github.com/nbubna/Case) package, which powers `preserve-case`!\n\n### `replace.createSearchRegExp(query, [options])`\n\nCreates a `RegExp` that matches for any case of the given `query` string.\nLike the other functions, `options.caseTypes` defaults to all types built into\nthe [`case`](https://github.com/nbubna/Case) package.\n\nYou may also pass a `flags` option for the `RegExp` flags (e.g. `flags: 'g'`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedwards1211%2Fpreserve-case","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjedwards1211%2Fpreserve-case","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedwards1211%2Fpreserve-case/lists"}