UNPKG

moy-fp

Version:
56 lines (53 loc) 1.34 kB
import curry from '../Function/curry' /** * a -> a -> Boolean */ const equals = curry( (b, a) => { if(Object.is(a, b)){ return true } const aType = Object.prototype.toString.call(a), bType = Object.prototype.toString.call(b) if(aType !== bType){ return false } if(aType === '[object Array]'){ if(a.length !== b.length){ return false } const length = a.length; for(let i = 0; i < length; i++){ if(!equals(b[i], a[i])){ return false } } return true } if(aType === '[object Object]'){ const aEntries = Object.entries(a), bEntries = Object.entries(b) if(aEntries.length !== bEntries.length){ return false } return equals(bEntries, aEntries) } if(aType === '[object Function]'){ return a.toString() === b.toString() } if(aType === '[object Date]'){ return a.valueOf() === b.valueOf() } if(aType === '[object RegExp]'){ return a.source === b.source && a.global === b.global && a.ignoreCase === b.ignoreCase && a.multiline === b.multiline && a.sticky === b.sticky && a.unicode === b.unicode && a.dotAll === b.dotAll } return false } ) export default equals