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

85.11% Statements 40/47
59.26% Branches 16/27
100% Functions 7/7
86.05% Lines 37/43

    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

    1×
    1×
    1×

    1×
    1×
    1×
    1×
    35×

    1×
    1×
    37×
    37×
    37×

    37×

    1×
    1×
    2×
    2×

    2×

    1×
    1×
    74×

    74×

    1×
    1×
    37×
    37×
    2×
    2×
    2×

    35×
    35×
    35×

    37×

    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", "./Exceptions/ArgumentException", "./Exceptions/ArgumentNullException"], factory);
        }
    })(function (require, exports) {
        "use strict";
        var ArgumentException_1 = require("./Exceptions/ArgumentException");
        var ArgumentNullException_1 = require("./Exceptions/ArgumentNullException");
        var VOID0 = void 0, DOT = '.', KEY = 'key', VALUE = 'value', ITEM = 'item', ITEM_1 = ITEM + '[1]', ITEM_KEY = ITEM + DOT + KEY, ITEM_VALUE = ITEM + DOT + VALUE, INVALID_KVP_MESSAGE = 'Invalid type.  Must be a KeyValuePair or Tuple of length 2.', CANNOT_BE_UNDEFINED = 'Cannot equal undefined.';
        function isKeyValuePair(kvp) {
            return kvp && kvp.hasOwnProperty(KEY) && kvp.hasOwnProperty(VALUE);
        }
        exports.isKeyValuePair = isKeyValuePair;
        function assertKey(key, name) {
            if (name === void 0) { name = ITEM; }
            assertNotUndefined(key, name + DOT + KEY);
            Iif (key === null)
                throw new ArgumentNullException_1.ArgumentNullException(name + DOT + KEY);
            return key;
        }
        exports.assertKey = assertKey;
        function assertTuple(tuple, name) {
            Eif (name === void 0) { name = ITEM; }
            Iif (tuple.length != 2)
                throw new ArgumentException_1.ArgumentException(name, 'KeyValuePair tuples must be of length 2.');
            assertKey(tuple[0], name);
        }
        exports.assertTuple = assertTuple;
        function assertNotUndefined(value, name) {
            Iif (value === VOID0)
                throw new ArgumentException_1.ArgumentException(name, CANNOT_BE_UNDEFINED);
            return value;
        }
        exports.assertNotUndefined = assertNotUndefined;
        function extractKeyValue(item, to) {
            var _ = this, key, value;
            if (item instanceof Array) {
                assertTuple(item);
                key = item[0];
                value = assertNotUndefined(item[1], ITEM_1);
            }
            else Eif (isKeyValuePair(item)) {
                key = assertKey(item.key);
                value = assertNotUndefined(item.value, ITEM_VALUE);
            }
            else {
                throw new ArgumentException_1.ArgumentException(ITEM, INVALID_KVP_MESSAGE);
            }
            return to(key, value);
        }
        exports.extractKeyValue = extractKeyValue;
        Object.defineProperty(exports, "__esModule", { value: true });
        exports.default = extractKeyValue;
    });
    //# sourceMappingURL=KeyValueExtract.js.map