index.js 387 B

12345678910111213141516
  1. 'use strict';
  2. var callBound = require('call-bind/callBound');
  3. var isRegex = require('is-regex');
  4. var $exec = callBound('RegExp.prototype.exec');
  5. var $TypeError = require('es-errors/type');
  6. module.exports = function regexTester(regex) {
  7. if (!isRegex(regex)) {
  8. throw new $TypeError('`regex` must be a RegExp');
  9. }
  10. return function test(s) {
  11. return $exec(regex, s) !== null;
  12. };
  13. };