Package Exports
- @putout/plugin-regexp
- @putout/plugin-regexp/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@putout/plugin-regexp) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@putout/plugin-regexp 
Regular expressions are patterns used to match character combinations in strings.
(c) MDN
🐊Putout plugin helps with Regular Expressions.
Install
npm i @putout/plugin-regexp -D
Rules
{
"rules": {
"regexp/apply-literal-notation": "on",
"regexp/optimize": "on",
"regexp/convert-to-string": "on",
"regexp/convert-replace-to-replace-all": "on",
"regexp/remove-useless-group": "on",
"regexp/remove-useless-regexp": "on"
}
}
regexp/optimize
❌ Example of incorrect code
const a = /(ab|ab)/;
✅ Example of correct code
const a = /(ab)/;
regexp/apply-literal-notation
❌ Example of incorrect code
const a = new RegExp('hello', 'i');
✅ Example of correct code
const a = /hello/i;
regexp/convert-to-string
❌ Example of incorrect code
'hello'.replace(/hello/, 'world');
✅ Example of correct code
'hello'.replace('hello', 'world');
regexp/convert-replace-to-replace-all
Simplify code according to string-replace-all.
❌ Example of incorrect code
'hello'.replace(/hello/g, 'world');
✅ Example of correct code
'hello'.replaceAll('hello', 'world');
regexp/remove-useless-group
❌ Example of incorrect code
/(hello)/.test(str);
✅ Example of correct code
/hello/.test(str);
regexp/remove-useless-regexp
❌ Example of incorrect code
const a = /^\.hello$/.test(str);
✅ Example of correct code
const a = str === '.hello';
License
MIT