"use strict";

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

var __assign = undefined && undefined.__assign || Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) {
            if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
        }
    }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
function parseHeaders(headers) {
    if (!headers) {
        return {};
    }
    if (Array.isArray(headers)) {
        return headers.reduce(function (acc, header) {
            return __assign({}, acc, (_a = {}, _a[header.name] = header.value, _a));
            var _a;
        }, {});
    } else if ((typeof headers === "undefined" ? "undefined" : _typeof(headers)) === 'object') {
        return headers;
    }
    var jsonVariables;
    try {
        jsonVariables = headers && headers.trim() !== '' ? JSON.parse(headers) : undefined;
    } catch (error) {
        /* tslint:disable-next-line */
        console.error("Headers are invalid JSON: " + error.message + ".");
    }
    if ((typeof jsonVariables === "undefined" ? "undefined" : _typeof(jsonVariables)) !== 'object') {
        /* tslint:disable-next-line */
        console.error('Headers are not a JSON object.');
    }
    return jsonVariables;
}
exports.parseHeaders = parseHeaders;
//# sourceMappingURL=parseHeaders.js.map