UNPKG

974 BJavaScriptView Raw
1'use strict';
2
3var assertPredicates = require('./utils/assertPredicates');
4
5/**
6 * Returns a function that calls predicates in the order until one of them will be satisfied, otherwise returns false.
7 *
8 * **Aliases** _or_
9 *
10 * @function any
11 *
12 * @example
13 * var is = require('predicates');
14 *
15 * var isStringOrNumber = is.any(is.string, is.number);
16 *
17 * isStringOrNumber(0); // true
18 * isStringOrNumber('string'); // true
19 * isStringOrNumber(undefined); // false
20 *
21 * @param {...Predicate} predicate
22 * @throws {TypeError} if not every predicate is a function
23 * @returns {Predicate}
24 */
25module.exports = function any() {
26 var predicates = Array.prototype.slice.call(arguments);
27 assertPredicates(predicates);
28
29 return function anyPredicate() {
30 var args = Array.prototype.slice.call(arguments);
31 return predicates.some(function anyPredicateTestingPredicate(predicate) {
32 return predicate.apply(this, args);
33 }, this);
34 };
35};