JSPM

  • Created
  • Published
  • Downloads 12409
  • Score
    100M100P100Q136102F
  • License MIT

putout plugin helps with regexp

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 NPM version

🐊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

❌ Incorrect code example

const a = /(ab|ab)/;

✅ Correct code Example

const a = /(ab)/;

regexp/apply-literal-notation

❌ Incorrect code example

const a = new RegExp('hello', 'i');

✅ Correct code Example

const a = /hello/i;

regexp/convert-to-string

❌ Incorrect code example

'hello'.replace(/hello/, 'world');

✅ Correct code Example

'hello'.replace('hello', 'world');

regexp/convert-replace-to-replace-all

Simplify code according to string-replace-all.

❌ Incorrect code example

'hello'.replace(/hello/g, 'world');

✅ Correct code Example

'hello'.replaceAll('hello', 'world');

regexp/remove-useless-group

❌ Incorrect code example

/(hello)/.test(str);

✅ Correct code Example

/hello/.test(str);

regexp/remove-useless-regexp

❌ Incorrect code example

const a = /^\.hello$/.test(str);

✅ Correct code Example

const a = str === '.hello';

License

MIT