UNPKG

rubico

Version:

[a]synchronous functional programming

8 lines (7 loc) 2.32 kB
/** * rubico v2.6.2 * https://github.com/a-synchronous/rubico * (c) 2019-2024 Richard Tong * rubico may be freely distributed under the MIT license. */ const __=Symbol.for("placeholder"),isArray=Array.isArray,isPromise=e=>null!=e&&"function"==typeof e.then,promiseAll=Promise.all.bind(Promise),spread2=e=>function([r,t]){return e(r,t)},curry2ResolveArg0=(e,r)=>function(t){return e(t,r)},curry2ResolveArg1=(e,r)=>function(t){return e(r,t)},curry2=function(e,r,t){return r==__?curry2ResolveArg0(e,t):curry2ResolveArg1(e,r)},objectKeysLength=e=>{let r=0;for(const t in e)r+=1;return r},symbolIterator=Symbol.iterator,sameValueZero=function(e,r){return e===r||e!=e&&r!=r},areIteratorsDeepEqual=function(e,r){let t=e.next(),n=r.next();if(t.done!=n.done)return!1;for(;!t.done;){if(!isDeepEqual(t.value,n.value))return!1;t=e.next(),n=r.next()}return n.done},areObjectsDeepEqual=function(e,r){if(objectKeysLength(e)!=objectKeysLength(r))return!1;for(const t in e)if(!isDeepEqual(e[t],r[t]))return!1;return!0},areArraysDeepEqual=function(e,r){const t=e.length;if(r.length!=t)return!1;let n=-1;for(;++n<t;)if(!isDeepEqual(e[n],r[n]))return!1;return!0},areValuesDeepEqual=function(e,r){const t=isArray(e),n=isArray(r);if(t||n)return t&&n&&areArraysDeepEqual(e,r);if(null==e||null==r)return sameValueZero(e,r);const u="string"==typeof e||e.constructor==String,o="string"==typeof r||r.constructor==String;if(u||o)return sameValueZero(e,r);const a="function"==typeof e[symbolIterator],s="function"==typeof r[symbolIterator];if(a||s)return a&&s&&areIteratorsDeepEqual(e[symbolIterator](),r[symbolIterator]());const l=e.constructor==Object,i=r.constructor==Object;return l||i?l&&i&&areObjectsDeepEqual(e,r):sameValueZero(e,r)},isDeepEqual=function(e,r){const t="function"==typeof e,n="function"==typeof r;return t&&n?function(t){const n=e(t),u=r(t),o=isPromise(n),a=isPromise(u);return o&&a?promiseAll([n,u]).then(spread2(areValuesDeepEqual)):o?n.then(curry2(areValuesDeepEqual,__,u)):a?u.then(curry2(areValuesDeepEqual,n,__)):areValuesDeepEqual(n,u)}:t?function(t){const n=e(t);return isPromise(n)?n.then(curry2(areValuesDeepEqual,__,r)):areValuesDeepEqual(n,r)}:n?function(t){const n=r(t);return isPromise(n)?n.then(curry2(areValuesDeepEqual,e,__)):areValuesDeepEqual(e,n)}:areValuesDeepEqual(e,r)};export default isDeepEqual;