UNPKG

988 BJavaScriptView Raw
1'use strict';
2
3var assertPredicates = require('./utils/assertPredicates');
4
5/**
6 * Returns a function that calls predicates and returns true if all of them are satisfied, otherwise returns false
7 *
8 * **Aliases** _and_
9 *
10 * @function all
11 *
12 * @example
13 * var is = require('predicates');
14 * var isNumberGreaterThan10 = is.all(is.number, is.greaterThan(10));
15 *
16 * isNumberGreaterThan10(0); // false
17 * isNumberGreaterThan10(11); // true
18 * isNumberGreaterThan10('11'); // false
19 *
20 * @param {...Predicate} predicate
21 * @throws {TypeError} if not every predicate is a function
22 * @returns {Predicate}
23 */
24module.exports = function all() {
25 var predicates = Array.prototype.slice.call(arguments);
26 assertPredicates(predicates);
27
28 return function allPredicate() {
29 var args = Array.prototype.slice.call(arguments);
30 return predicates.every(function allPredicateTestingPredicate(predicate) {
31 return predicate.apply(this, args);
32 }, this);
33 };
34};