# all files / TypeScript.NET/dist/commonjs/System/ Types.js

48.09% Statements 63/131
19.32% Branches 17/88
33.33% Functions 8/24
43.24% Lines 48/111

    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
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177

    2×

    11×

    1×

    1×

    1×

    1×
    1×

    1×

    1×

    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×

    1×
    1×
    4×
    4×

    1×
    1×

    1×
    1×
    4×

    1×
    1×

    1×
    1×

    1×
    1×

    1×
    1×

    1×
    1×

    1×
    1×

    1×
    1×

    1×
    1×

    1×

    1×
    1×
    1×

     /*!
     * @author electricessence / https://github.com/electricessence/
     * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
     */
    'use strict';

    var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Eif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

    var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

    function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

    var VOID0 = void 0,
        _BOOLEAN = _typeof(true),
        _NUMBER = _typeof(0),
        _STRING = _typeof(""),
        _OBJECT = _typeof({}),
        _UNDEFINED = typeof VOID0 === "undefined" ? "undefined" : _typeof(VOID0),
        _FUNCTION = _typeof(function () {}),
        LENGTH = "length";
    var typeInfoRegistry = {};

    var TypeInfo = function () {
        function TypeInfo(target) {
            _classCallCheck(this, TypeInfo);

            var _ = this;
            _.isBoolean = false;
            _.isNumber = false;
            _.isString = false;
            _.isTrueNaN = false;
            _.isObject = false;
            _.isFunction = false;
            _.isUndefined = false;
            _.isNull = false;
            _.isPrimitive = false;
            switch (_.type = typeof target === "undefined" ? "undefined" : _typeof(target)) {
                case _BOOLEAN:
                    _.isBoolean = true;
                    _.isPrimitive = true;
                    break;
                case _NUMBER:
                    _.isNumber = true;
                    _.isTrueNaN = isNaN(target);
                    _.isFinite = isFinite(target);
                    _.isValidNumber = !_.isTrueNaN;
                    _.isPrimitive = true;
                    break;
                case _STRING:
                    _.isString = true;
                    _.isPrimitive = true;
                    break;
                case _OBJECT:
                    _.target = target;
                    if (target === null) {
                        _.isNull = true;
                        _.isNullOrUndefined = true;
                        _.isPrimitive = true;
                    } else {
                        _.isObject = true;
                    }
                    break;
                case _FUNCTION:
                    _.target = target;
                    _.isString = true;
                    break;
                case _UNDEFINED:
                    _.isUndefined = true;
                    _.isNullOrUndefined = true;
                    _.isPrimitive = true;
                    break;
                default:
                    throw "Fatal type failure.  Unknown type: " + _.type;
            }
            Object.freeze(_);
        }

        _createClass(TypeInfo, [{
            key: "member",
            value: function member(name) {
                var t = this.target;
                return TypeInfo.getFor(t && name in t ? t[name] : undefined);
            }
        }], [{
            key: "getFor",
            value: function getFor(target) {
                var type = typeof target === "undefined" ? "undefined" : _typeof(target);
                switch (type) {
                    case _OBJECT:
                    case _FUNCTION:
                        return new TypeInfo(target);
                }
                var info = typeInfoRegistry[type];
                if (!info) typeInfoRegistry[type] = info = new TypeInfo(target);
                return info;
            }
        }]);

        return TypeInfo;
    }();

    exports.TypeInfo = TypeInfo;
    var Type;
    (function (Type) {
        Type.BOOLEAN = _BOOLEAN;
        Type.NUMBER = _NUMBER;
        Type.STRING = _STRING;
        Type.OBJECT = _OBJECT;
        Type.UNDEFINED = _UNDEFINED;
        Type.FUNCTION = _FUNCTION;
        function isBoolean(value) {
            return (typeof value === "undefined" ? "undefined" : _typeof(value)) === _BOOLEAN;
        }
        Type.isBoolean = isBoolean;
        function isNumber(value, allowNaN) {
            Iif (allowNaN === VOID0) allowNaN = true;
            return (typeof value === "undefined" ? "undefined" : _typeof(value)) === _NUMBER && (allowNaN || !isNaN(value));
        }
        Type.isNumber = isNumber;
        function isTrueNaN(value) {
            return (typeof value === "undefined" ? "undefined" : _typeof(value)) === _NUMBER && isNaN(value);
        }
        Type.isTrueNaN = isTrueNaN;
        function isString(value) {
            return (typeof value === "undefined" ? "undefined" : _typeof(value)) === _STRING;
        }
        Type.isString = isString;
        function isPrimitive(value) {
            var t = typeof value === "undefined" ? "undefined" : _typeof(value);
            switch (t) {
                case _BOOLEAN:
                case _STRING:
                case _NUMBER:
                case _UNDEFINED:
                    return true;
                case _OBJECT:
                    return value === null;
            }
            return false;
        }
        Type.isPrimitive = isPrimitive;
        function isFunction(value) {
            return (typeof value === "undefined" ? "undefined" : _typeof(value)) === _FUNCTION;
        }
        Type.isFunction = isFunction;
        function isObject(value) {
            var allowNull = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];

            return (typeof value === "undefined" ? "undefined" : _typeof(value)) === _OBJECT && (allowNull || value !== null);
        }
        Type.isObject = isObject;
        function numberOrNaN(value) {
            return isNaN(value) ? NaN : value;
        }
        Type.numberOrNaN = numberOrNaN;
        function of(target) {
            return TypeInfo.getFor(target);
        }
        Type.of = of;
        function hasMember(value, property) {
            return value && !isPrimitive(value) && property in value;
        }
        Type.hasMember = hasMember;
        function hasMemberOfType(instance, property, type) {
            return hasMember(instance, property) && _typeof(instance[property]) === type;
        }
        Type.hasMemberOfType = hasMemberOfType;
        function isArrayLike(instance) {
            return instance instanceof Array || Type.isString(instance) || !Type.isFunction(instance) && hasMember(instance, LENGTH);
        }
        Type.isArrayLike = isArrayLike;
    })(Type || (Type = {}));
    Object.freeze(Type);
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.default = Type;
    //# sourceMappingURL=Types.js.map