@putout/operator-regexp
🐊Putout operator adds ability to check if provided regexp can be converted to string without losing it's sense
Last updated a year ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @putout/operator-regexp 
SYNC missed versions from official npm registry.

@putout/operator-regexp NPM version

🐊Putout operator adds ability to determine that provided RegExp can be converted to String without losing it's sense.

It is used for example in regexp/convert-replace-to-relace-all:

-'hello'.replace(/hello/g, 'world');
+'hello'.replaceAll('hello', 'world');

Install

npm i putout @putout/operator-regexp

API

isSimpleRegexp(regexp: RegExp)

const {operator} = require('putout');
const {isSimpleRegExp} = operator;

isSimpleRegExp(/hello world/);
// returns
true;

isSimpleRegExp(/^hello/);
// returns
false;

transformRegExp(regexp: String, plugin: Traverser)

transformRegExp('[aab]', {
    report,
    fix,
    traverse,
});

getStringFromRegExp(pattern: String)

To avoid errors like this:

SyntaxError: Expecting Unicode escape sequence \uXXXX

const string = getStringFromRegExp(regexpNode);

License

MIT

Current Tags

  • 5.2.0                                ...           latest (5 months ago)

7 Versions

  • 5.2.0                                ...           5 months ago
  • 5.1.0                                ...           7 months ago
  • 5.0.0                                ...           8 months ago
  • 4.0.0                                ...           a year ago
  • 3.0.0                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Total 15
Today 0
This Week 4
This Month 14
Last Day 1
Last Week 8
Last Month 0
Dependencies (1)
Dev Dependencies (10)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE