{"name":"@putout/plugin-regexp","version":"13.2.1","keywords":["putout","putout-plugin","plugin","regexp"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/plugin-regexp@13.2.1","maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-regexp#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"f63aeeffc538b931f2ffdfe3d89690b9982921ca","tarball":"http://registry-npm.ywwl.com/@putout/plugin-regexp/download/@putout/plugin-regexp-13.2.1.tgz","fileCount":22,"integrity":"sha512-JFzjewYVh/mqYA5FJnxAx6xInCybPOWrznffUEj6kCYeD+DN0IPkQlbRcx5YllDD0PhBzkbq/1U4xg8BLivpFg==","signatures":[{"sig":"MEYCIQDTYgCDDKhW7XiANId+3TjKu8+lUX9B2KN7kdJ1oU6kkQIhAN2gucAON9A2oN4YpFN5J8qhcLfgkBtGIUoDaJH/wi2t","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":28503,"size":7295,"noattachment":false,"key":"/@putout/plugin-regexp/-/@putout/plugin-regexp-13.2.1.tgz"},"main":"lib/index.js","type":"module","engines":{"node":">=22"},"gitHead":"ff2f24f70e27b5b46fd7748ee6c4f9c27ea39ee7","release":false,"scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","coverage":"madrun coverage","fix:lint":"madrun fix:lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","watch:test":"madrun watch:test"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"changelog":false,"repository":{"url":"git+https://github.com/coderaiser/putout.git","type":"git"},"_npmVersion":"11.4.2","description":"🐊Putout plugin helps with regexp","directories":{},"_nodeVersion":"22.21.1","dependencies":{"try-catch":"^4.0.0","regexp-tree":"^0.1.21"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","eslint":"^10.0.0-alpha.0","madrun":"^12.0.0","nodemon":"^3.0.1","@putout/test":"^15.0.0","eslint-plugin-n":"^17.0.0","@putout/eslint-flat":"^3.0.0","eslint-plugin-putout":"^29.0.0","@putout/plugin-remove-useless-escape":"*"},"peerDependencies":{"putout":">=41"},"_npmOperationalInternal":{"tmp":"tmp/plugin-regexp_13.2.1_1768678841679_0.6334772064878582","host":"s3://npm-registry-packages-npm-production"},"readme":"# @putout/plugin-regexp [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-regexp.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/plugin-regexp \"npm\"\n\n> Regular expressions are patterns used to match character combinations in strings.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin helps with **Regular Expressions**.\n\n## Install\n\n```\nnpm i @putout/plugin-regexp -D\n```\n\n## Rules\n\n- ✅ [apply-character-class](#apply-character-class);\n- ✅ [apply-ends-with](#apply-ends-with);\n- ✅ [apply-global-regexp-to-replace-al](#apply-global-regexp-to-replace-all);\n- ✅ [apply-literal-notation](#apply-literal-notation);\n- ✅ [apply-starts-with](#apply-starts-with);\n- ✅ [convert-replace-to-replace-all](#convert-replace-to-replace-all);\n- ✅ [convert-to-string](#convert-to-string);\n- ✅ [optimize](#optimize);\n- ✅ [remove-useless-group](#remove-useless-group);\n- ✅ [remove-useless-regexp](#remove-useless-regexp);\n- ✅ [remove-useless-escape](#remove-useless-escape);\n- ✅ [remove-duplicates-from-character-class](#remove-duplicates-from-character-class);\n\n## Config\n\n```json\n{\n    \"rules\": {\n        \"regexp/apply-character-class\": \"on\",\n        \"regexp/apply-global-regexp-to-replace-all\": \"on\",\n        \"regexp/apply-literal-notation\": \"on\",\n        \"regexp/apply-starts-with\": \"on\",\n        \"regexp/apply-ends-with\": \"on\",\n        \"regexp/optimize\": \"on\",\n        \"regexp/convert-to-string\": \"on\",\n        \"regexp/convert-replace-to-replace-all\": \"on\",\n        \"regexp/remove-useless-group\": \"on\",\n        \"regexp/remove-useless-escape\": \"on\",\n        \"regexp/remove-useless-regexp\": \"on\",\n        \"regexp/remove-duplicates-from-character-class\": \"on\"\n    }\n}\n```\n\n## optimize\n\n### ❌ Example of incorrect code\n\n```js\nconst a = /(ab|ab)/;\n```\n\n### ✅ Example of correct code\n\n```js\nconst a = /(ab)/;\n```\n\n## apply-character-class\n\nCheckout in:\n\n- 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/af6302761114152dee215625ff411825/fb2a0589b29d80a7c76fb05eb9ace66511a5e8bb).\n- [AST Explorer](https://astexplorer.net/#/gist/86288d07002d1151c7eac529c0b85f1e/ad57c586193f19e56d07b1d18725ec969388dde2).\n\n### ❌ Example of incorrect code\n\n```js\n/\\)|\\(/g;\n```\n\n### ✅ Example of correct code\n\n```js\n/[)(]/g;\n```\n\n## apply-global-regexp-to-replace-all\n\n> `Uncaught TypeError: String.prototype.replaceAll called with a non-global RegExp argument`\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Requires_global_RegExp)\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8c759e3c8d19d660ddb01bda04d75c8b/f1d0f3a6d491f034308f5f3a375900b0a620a3b3).\n\n### ❌ Example of incorrect code\n\n```js\n's'.replaceAll(/hello/, 's');\n'abc'.matchAll(/./);\n```\n\n### ✅ Example of correct code\n\n```js\n's'.replaceAll(/hello/g, 's');\n'abc'.matchAll(/./g);\n```\n\n## apply-literal-notation\n\n### ❌ Example of incorrect code\n\n```js\nconst a = new RegExp('hello', 'i');\n```\n\n### ✅ Example of correct code\n\n```js\nconst a = /hello/i;\n```\n\n## apply-starts-with\n\n> The `startsWith()` method determines whether a string begins with the characters of a specified string, returning `true` or `false` as appropriate.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)\n\n**RegExp** is overkill for such a simple task as determining that string located at the beginning. Check it out in 🐊 [**Putout Editor**](https://putout.cloudcmd.io/#/gist/79e3e41c3491fb8c45fb03580e42ef20/89971d2d6528ee78df4c2a0d6271179560f76cc1).\n\n### ❌ Example of incorrect code\n\n```js\n/^hello/.test(a);\n```\n\n### ✅ Example of correct code\n\n```js\na.startsWith('hello');\n```\n\n### Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout**| [`regexp/apply-starts-with`](https://github.com/coderaiser/putout/tree/master/packages/plugin-regexp#apply-starts-with)| ✅\n🦕 **TypeScript ESLint** | [`prefer-string-starts-ends-with`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md#prefer-string-starts-ends-with) | ✅\n\n## apply-ends-with\n\n> The `startsWith()` method determines whether a string ends with the characters of a specified string, returning `true` or `false` as appropriate.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)\n\n**RegExp** is overkill for such a simple task as determining that string located at the end.\n\n### ❌ Example of incorrect code\n\n```js\n/hello$/.test(a);\n```\n\n### ✅ Example of correct code\n\n```js\na.endsWith('hello');\n```\n\n### Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout**| [`regexp/apply-ends-with`](https://github.com/coderaiser/putout/tree/master/packages/plugin-regexp#apply-ends-with)| ✅\n🦕 **TypeScript ESLint** | [`prefer-string-starts-ends-with`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md#prefer-string-starts-ends-with) | ✅\n\n## convert-to-string\n\n### ❌ Example of incorrect code\n\n```js\n'hello'.replace(/hello/, 'world');\n```\n\n### ✅ Example of correct code\n\n```js\n'hello'.replace('hello', 'world');\n```\n\n## convert-replace-to-replace-all\n\nSimplify code according to [string-replace-all](https://github.com/tc39/proposal-string-replaceall).\n\n### ❌ Example of incorrect code\n\n```js\n'hello'.replace(/hello/g, 'world');\n```\n\n### ✅ Example of correct code\n\n```js\n'hello'.replaceAll('hello', 'world');\n```\n\n## remove-useless-group\n\n### ❌ Example of incorrect code\n\n```js\n/(hello)/.test(str);\n```\n\n### ✅ Example of correct code\n\n```js\n/hello/.test(str);\n```\n\n## remove-useless-escape\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/af9d1c774c3691aface974406717b32a/e9fc8a985e0195ecc27d70c748e5d4497be91265).\n\n### ❌ Example of incorrect code\n\n```js\nconst cleanText = code.replaceAll(/[,;\\(\\)]/g, '');\n```\n\n### ✅ Example of correct code\n\n```js\nconst cleanText = code.replaceAll(/[,;()]/g, '');\n```\n\n### Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout**| [`regexp/remove-useless-escape`](https://github.com/coderaiser/putout/tree/master/packages/plugin-regexp/#remove-useless-escape)| ✅\n⏣ **ESLint** | [`no-useless-escape`](https://eslint.org/docs/rules/no-useless-escape) | ❌\n\n## remove-useless-regexp\n\n### ❌ Example of incorrect code\n\n```js\nconst a = /^\\.hello$/.test(str);\n```\n\n### ✅ Example of correct code\n\n```js\nconst a = str === '.hello';\n```\n\n## remove-duplicates-from-character-class\n\nCheckout in [AST Explorer](https://astexplorer.net/#/gist/634783e99f6a9432e375ac8ad96647d9/a889735af932bd9f88f953596bec80d3a714415f).\n\n### ❌ Example of incorrect code\n\n```js\n/[aaabb]/.test(str);\n```\n\n### ✅ Example of correct code\n\n```js\n/[ab]/.test(str);\n```\n\n## License\n\nMIT\n","publish_time":1768678841848,"_cnpm_publish_time":1768678841848,"dist-tags":{"latest":"14.0.0"}}