1.0.3 • Published 1 year ago

regexp-with-timeout v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

regexp-with-timeout

  • This package is created to solve the issue of backtracking in regex.
  • There are some package also on npm, but either they reduces performance or they are not for commonjs environment.
  • This package is created for commonJs environment.

Follow below steps to use this package:

1) Install npm package:

npm install regexp-with-timeout

2) Import this package in your project/file:

const regExp = require('regexp-with-timeout')({limit: maxWaitTimeForRegex}); //maxWaitTimeForRegex is time limit to regex

3) Wrap calling to test method of this package in try catch block:

   let isValidActionStatement = false;
   try {
     isValidActionStatement = await regExp.test(regexInString,flags,string);
   } catch (exception) {
    //write your code in case of regex backtrack (timeout) issue occurs
   }
   //after successful test of regex write your code here

Notes:

  • Time limit is in second.
  • Default time limit is 1 sec.
  • Pass regex to function in the format of string, eg- 'a-z*'
  • Pass flags in the form of string, eg- 'g'.
1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago