You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
839 B

4 years ago
  1. import _cloneRegExp from "./internal/_cloneRegExp.js";
  2. import _curry2 from "./internal/_curry2.js";
  3. import _isRegExp from "./internal/_isRegExp.js";
  4. import toString from "./toString.js";
  5. /**
  6. * Determines whether a given string matches a given regular expression.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.12.0
  11. * @category String
  12. * @sig RegExp -> String -> Boolean
  13. * @param {RegExp} pattern
  14. * @param {String} str
  15. * @return {Boolean}
  16. * @see R.match
  17. * @example
  18. *
  19. * R.test(/^x/, 'xyz'); //=> true
  20. * R.test(/^y/, 'xyz'); //=> false
  21. */
  22. var test =
  23. /*#__PURE__*/
  24. _curry2(function test(pattern, str) {
  25. if (!_isRegExp(pattern)) {
  26. throw new TypeError('‘test’ requires a value of type RegExp as its first argument; received ' + toString(pattern));
  27. }
  28. return _cloneRegExp(pattern).test(str);
  29. });
  30. export default test;