"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var emittedWarnings = new Set();
exports.warnOnce = function (message) {
    if (emittedWarnings.has(message)) {
        return;
    }
    emittedWarnings.add(message);
    console.warn(message);
};
exports.isValue = function (value) {
    return !exports.isNullOrUndefined(value);
};
exports.isNullOrUndefined = function (value) { return value === null || value === undefined; };
function is() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    if (args.length === 2) {
        return args[1](args[0]);
    }
    return function (input) { return args[0](input); };
}
exports.is = is;
exports.parseQueryParametersList = function (url) {
    if (!url) {
        return [];
    }
    var query = "";
    var queryLocation = url.indexOf("?");
    if (queryLocation < 0) {
        query = url;
    }
    else {
        query = url.substr(queryLocation + 1);
    }
    return query.split("&").map(function (param) {
        var matches = param.match(/^([^=]+)=([^=]+)$/);
        if (matches !== null) {
            var key = matches[1];
            var value = matches[2];
            if (value === "true") {
                value = true;
            }
            else if (value === "false") {
                value = false;
            }
            return {
                key: key,
                value: value,
            };
        }
        return {
            key: param,
            value: true,
        };
    });
};
function parseQueryParameters(url) {
    var params = exports.parseQueryParametersList(url);
    return params.reduce(function (allParams, _a) {
        var key = _a.key, value = _a.value;
        allParams[key] = value;
        return allParams;
    }, {});
}
exports.parseQueryParameters = parseQueryParameters;
function generateId() {
    var S4 = function () {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    };
    return (S4() +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        S4() +
        S4());
}
exports.generateId = generateId;
exports.noop = function () { };
exports.delay = function (time) {
    return new Promise(function (resolve) { return setTimeout(resolve, time); });
};
exports.debounceWithAnimationFrame = function (func) {
    var frame;
    var callArgs;
    return function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        if (frame) {
            callArgs = args;
            return;
        }
        frame = window.requestAnimationFrame(function () {
            func.apply(undefined, callArgs);
            frame = undefined;
            callArgs = undefined;
        });
    };
};
exports.valueOrDefault = function (value, otherwise) {
    if (!exports.isNullOrUndefined(value)) {
        return value;
    }
    return otherwise;
};
exports.getGlobalObject = function () {
    if (typeof self !== "undefined") {
        return self;
    }
    if (typeof window !== "undefined") {
        return window;
    }
    if (typeof global !== "undefined") {
        return global;
    }
    throw new Error("unable to locate global object");
};
