timeout-this

0.0.1 • Public • Published

timeout-this

Timeout synchronous code in Node.js

This module can be used to add a timeout to a method. For instance, if you want to prevent Regex.prototype.exec to run longer than 1 second (maybe to prevent Regexp DoS), you can do:

const TimeoutThis = require('timeout-this');
TimeoutThis.makeTimeoutable(RegExp.prototype, 'exec');

Then, if you pass an additional numeric argument to Regex.prototype.exec, it will be used as timeout in milliseconds:

const validateEmailFormat = function ( string ) {

            const emailExpression = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            return emailExpression.exec( string, 1000 );
};

Readme

Keywords

Package Sidebar

Install

npm i timeout-this

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

20.7 kB

Total Files

12

Last publish

Collaborators

  • vdeturckheim