All files predicates.js

52.17% Statements 12/23
100% Branches 4/4
66.67% Functions 10/15
58.82% Lines 10/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47            12x       10x       16x       16x     5x 2x                             64x 25x       3x 2x      
import {
  every,
  has,
} from 'lodash';
 
export function isNumber(value) {
  return typeof value === 'number';
}
 
export function isString(value) {
  return typeof value === 'string';
}
 
export function isArray(value) {
  return Array.isArray(value);
}
 
export function isIndexed(value) {
  return isArray(value) ||  isString(value);
}
 
export function isEven(val) { return val % 2 === 0 }
export function isOdd(val)  { return !isEven(val) }
 
export function hasKeys(...keys) {
  return obj => {
    return every(keys, key => has(obj, key));
  }
}
export function hasValidatedKeys(...keys) {
  const fun = () => hasKeys(keys)
  fun.message = `Must have values for: ${keys.join(', ')}`
  return fun;
}
 
// notice the intentional loose != operator.  Allows us to distinguish between
// null, undefined, and everything else.
export function existy(x) { return x != null }; 
export function truthy(x) { return (x !== false) && existy(x) };
 
// allows you to reverse a predicate
export function complement(pred) {
  return function(...args) {
    return !pred.apply(null, args);
  }
}