All files / src/renderer areEquivalentValues.ts

100% Statements 33/33
100% Branches 34/34
100% Functions 1/1
100% Lines 31/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 9520x   594x   193x     401x     16x     385x     19x           366x         366x   366x     32x   31x       1x         334x     159x   12x       147x   251x   108x       39x         175x     35x   35x   35x   2x       33x   40x   40x   27x       6x         140x  
export default function areEquivalentValues(v1: any = null, v2: any = null): boolean {
 
    if (v1 === v2) {
 
        return true;
    }
 
    if (v1 === null &&
        v2 !== null) {
 
        return false;
    }
 
    if (v1 !== null &&
        v2 === null) {
 
        return false;
    }
 
    const {
        patcher: patcher1,
        values: values1
    } = v1;
 
    const {
        patcher: patcher2,
        values: values2
    } = v2;
 
    if (patcher1 !== undefined &&
        patcher2 !== undefined) {
 
        if (patcher1 === patcher2) {
 
            return areEquivalentValues(values1, values2);
        }
        else {
 
            return false;
        }
    }
 
    // If both values are array
    if (Array.isArray(v1) &&
        Array.isArray(v2)) {
 
        if (v1.length !== v2.length) {
 
            return false;
        }
        else {
 
            for (let i = 0; i < v1.length; ++i) {
 
                if (!areEquivalentValues(v1[i], v2[i])) {
 
                    return false;
                }
            }
 
            return true;
        }
    }
 
    // If both values are objects
    if (typeof v1 === 'object' &&
        typeof v2 === 'object') {
 
        const k1 = Object.keys(v1);
 
        const k2 = Object.keys(v2);
 
        if (k1.length !== k2.length) {
 
            return false;
        }
        else {
 
            for (let i = 0; i < k1.length; ++i) {
 
                const k = k1[i];
 
                if (!areEquivalentValues(v1[k], v2[k])) {
 
                    return false;
                }
            }
 
            return true;
        }
    }
 
    // Types do not match
    return false;
}