# all files / TypeScript.NET/source/System/ Compare.js

42.19% Statements 27/64
33.33% Branches 27/81
80% Functions 4/5
41.38% Lines 24/58

    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

    1×
    1×
    1×

    1×
    1×
    1×
    1×
    739×
    739×

    1×
    1×
    1×
    113×
    113×
    27×
    86×

    86×

    86×
    42×
    44×
    44×

    1×
    1×

    1×

     /*!
     * @author electricessence / https://github.com/electricessence/
     * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
     */
    (function (factory) {
        Eif (typeof module === 'object' && typeof module.exports === 'object') {
            var v = factory(require, exports); Iif (v !== undefined) module.exports = v;
        }
        else if (typeof define === 'function' && define.amd) {
            define(["require", "exports", "./Types"], factory);
        }
    })(function (require, exports) {
        "use strict";
        var Types_1 = require("./Types");
        var isTrueNaN = Types_1.Type.isTrueNaN;
        var VOID0 = void 0;
        function areEqual(a, b, strict) {
            if (strict === void 0) { strict = true; }
            return a === b
                || !strict && a == b
                || isTrueNaN(a) && isTrueNaN(b);
        }
        exports.areEqual = areEqual;
        var COMPARE_TO = "compareTo";
        function compare(a, b, strict) {
            Eif (strict === void 0) { strict = true; }
            if (areEqual(a, b, strict))
                return 0;
            Iif (a && Types_1.Type.hasMember(a, COMPARE_TO))
                return a.compareTo(b);
            else Iif (b && Types_1.Type.hasMember(b, COMPARE_TO))
                return -b.compareTo(a);
            if (a > b || strict && (a === 0 && b == 0 || a === null && b === VOID0))
                return 1;
            Eif (b > a || strict && (b === 0 && a == 0 || b === null && a === VOID0))
                return -1;
            return NaN;
        }
        exports.compare = compare;
        function areEquivalent(a, b, nullEquivalency, extraDepth) {
            if (nullEquivalency === void 0) { nullEquivalency = true; }
            if (extraDepth === void 0) { extraDepth = 0; }
            if (areEqual(a, b, true))
                return true;
            if (a === null || a === VOID0 || b == null || b === VOID0) {
                if (!nullEquivalency)
                    return false;
                if (Types_1.Type.isObject(a)) {
                    return !Object.keys(a).length;
                }
                if (Types_1.Type.isObject(b)) {
                    return !Object.keys(b).length;
                }
                return (a === null || a === VOID0) && (b == null || b === VOID0);
            }
            if (Types_1.Type.isObject(a) && Types_1.Type.isObject(b)) {
                var aKeys = Object.keys(a), bKeys = Object.keys(b), len = aKeys.length;
                if (len != bKeys.length)
                    return false;
                aKeys.sort();
                bKeys.sort();
                for (var i = 0; i < len; i++) {
                    var key = aKeys[i];
                    if (key !== bKeys[i] || !areEqual(a[key], b[key], true))
                        return false;
                }
                if (extraDepth > 0) {
                    for (var _i = 0, aKeys_1 = aKeys; _i < aKeys_1.length; _i++) {
                        var key = aKeys_1[_i];
                        if (!areEquivalent(a[key], b[key], nullEquivalency, extraDepth - 1))
                            return false;
                    }
                }
                return true;
            }
            return false;
        }
        exports.areEquivalent = areEquivalent;
    });
    //# sourceMappingURL=Compare.js.map