UNPKG

924 BJavaScriptView Raw
1'use strict';
2
3var isFunction = require('./function'),
4 handleCurry = require('./utils/handleCurry');
5
6/**
7 * Negates result of a predicate
8 *
9 * **Aliases** _negate_
10 *
11 * @function not
12 *
13 * @example
14 * var is = require('predicates');
15 *
16 * var isNotEmpty = is.not(is.empty);
17 * isNotEmpty([1, 2]);// true
18 * // same as
19 * is.not(is.empty, [1, 2]); // true
20 * isNotEmpty(''); // false
21 *
22 * @param {Predicate} predicate
23 * @param {*} [value]
24 * @param {...*} [additionalArgs] additional arguments passed to the predicate
25 * @returns {(Boolean|Predicate)} returns bool if at least two arguments provided, otherwise a predicate
26 */
27module.exports = function isNot(predicate) {
28 if (!isFunction(predicate)) {
29 throw new TypeError('Predicate must be a function');
30 }
31
32 return handleCurry.call(this, arguments, function isNotPredicateNegation() {
33 return !predicate.apply(this, arguments);
34 });
35};