crocks
Version:
A collection of well known Algebraic Datatypes for your utter enjoyment.
30 lines (23 loc) • 813 B
JavaScript
/** @license ISC License (c) copyright 2017 original and current authors */
/** @author Karthik Iyengar (karthikiyengar) */
var curry = require('../core/curry')
var equals = require('../core/equals')
var isDefined = require('../core/isDefined')
var isEmpty = require('../core/isEmpty')
var isInteger = require('../core/isInteger')
var isNil = require('../core/isNil')
var isString = require('../core/isString')
// propEq: (String | Integer) -> a -> b -> Boolean
function propEq(key, value, x) {
if(!(isString(key) && !isEmpty(key) || isInteger(key))) {
throw new TypeError(
'propEq: Non-empty String or Integer required for first argument'
)
}
if(isNil(x)) {
return false
}
var target = x[key]
return isDefined(target) && equals(target, value)
}
module.exports = curry(propEq)