File indexing completed on 2025-01-26 05:28:00

0001 export const isNil = x => x == null
0002 
0003 
0004 export const cancelablePromise = /* istanbul ignore next */ (promise) => {
0005   let hasCanceled = false
0006 
0007   const wrappedPromise = new Promise((resolve, reject) => {
0008     promise.then(val => (hasCanceled ? reject({ isCanceled: true }) : resolve(val)))
0009     promise.catch(error => (hasCanceled ? reject({ isCanceled: true }) : reject(error)))
0010   })
0011 
0012   return {
0013     promise: wrappedPromise,
0014     cancel() {
0015       hasCanceled = true
0016     },
0017   }
0018 }
0019 
0020 
0021 const hasOwn = /* istanbul ignore next */ Object.prototype.hasOwnProperty
0022 
0023 const is = /* istanbul ignore next */ (x, y) => {
0024   if (x === y) {
0025     return x !== 0 || y !== 0 || 1 / x === 1 / y
0026   }
0027   return x !== x && y !== y // eslint-disable-line
0028 }
0029 
0030 
0031 export const shallowEqual = /* istanbul ignore next */ (objA, objB) => {
0032   if (is(objA, objB)) return true
0033 
0034   if (typeof objA !== 'object' || objA === null
0035     || typeof objB !== 'object' || objB === null) {
0036     return false
0037   }
0038 
0039   const keysA = Object.keys(objA)
0040   const keysB = Object.keys(objB)
0041 
0042   if (keysA.length !== keysB.length) return false
0043 
0044   for (let i = 0; i < keysA.length; i++) { //eslint-disable-line
0045     if (!hasOwn.call(objB, keysA[i])
0046       || !is(objA[keysA[i]], objB[keysA[i]])) {
0047       return false
0048     }
0049   }
0050 
0051   return true
0052 }