1 | ;
|
2 |
|
3 | var isRegexp = require('./regexp'),
|
4 | handleCurry = require('./utils/handleCurry');
|
5 |
|
6 | /**
|
7 | * Checks whether a value matches a regexp
|
8 | *
|
9 | * **Aliases** _match_
|
10 | *
|
11 | * @function matches
|
12 | *
|
13 | * @example
|
14 | * var is = require('predicates');
|
15 | *
|
16 | * var isWindows9x = is.matches(/^Windows 9/);
|
17 | *
|
18 | * isWindows9x('Windows 9'); // true - :D
|
19 | * // same as
|
20 | * is.matches(/^Windows 9/, 'Windows 9'); // also true - hue hue
|
21 | *
|
22 | * isWindows9x('Windows 10); // false
|
23 | *
|
24 | * @param {RegExp} regexp
|
25 | * @param {String} [value]
|
26 | * @throws {TypeError} if regexp is not a regexp
|
27 | * @returns {(Boolean|Predicate)} bool if at least two arguments provided, otherwise a predicate
|
28 | */
|
29 | module.exports = function matches(regexp) {
|
30 | if (!isRegexp(regexp)) {
|
31 | throw new TypeError('Regexp must be a RegExp object');
|
32 | }
|
33 |
|
34 | return handleCurry.call(this, arguments, function matchesPredicate(value) {
|
35 | return regexp.test(value);
|
36 | });
|
37 | };
|