index.js 434 B

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