UNPKG

crocks

Version:

A collection of well known Algebraic Datatypes for your utter enjoyment.

31 lines (25 loc) 1.01 kB
/** @license ISC License (c) copyright 2018 original and current authors */ /** @author Ian Hofmann-Hicks (evilsoft) */ var curry = require('../core/curry') var isEmpty = require('../core/isEmpty') var isInteger = require('../core/isInteger') var isNil = require('../core/isNil') var isPredOrFunc = require('../core/isPredOrFunc') var isString = require('../core/isString') var predOrFunc = require('../core/predOrFunc') // propSatisfies: (String | Integer) -> (a -> Boolean) -> b -> Boolean // propSatisfies: (String | Integer) -> Pred a -> b -> Boolean function propSatisfies(key, pred, x) { if(!(isString(key) && !isEmpty(key) || isInteger(key))) { throw new TypeError( 'propSatisfies: Non-empty String or Integer required for first argument' ) } if(!isPredOrFunc(pred)) { throw new TypeError( 'propSatisfies: Pred or predicate function required for second argument' ) } return isNil(x) ? false : !!predOrFunc(pred, x[key]) } module.exports = curry(propSatisfies)