/**
 * @fileoverview added by tsickle
 * Generated from: utils/common-util.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/*!
 * Copyright 2020 VMware, Inc.
 * SPDX-License-Identifier: BSD-2-Clause
 */
var CommonUtil = /** @class */ (function () {
    function CommonUtil() {
    }
    /**
     * Rounds number to given floating point, 2 by default.
     * @param value number from float data type
     * @param digits how many numbers will be shown after decimal point
     */
    /**
     * Rounds number to given floating point, 2 by default.
     * @param {?} value number from float data type
     * @param {?=} digits how many numbers will be shown after decimal point
     * @return {?}
     */
    CommonUtil.roundTo = /**
     * Rounds number to given floating point, 2 by default.
     * @param {?} value number from float data type
     * @param {?=} digits how many numbers will be shown after decimal point
     * @return {?}
     */
    function (value, digits) {
        if (digits === void 0) { digits = 2; }
        if (!value) {
            value = 0;
        }
        return Number(Math.round(Number(value + 'e' + digits)) + 'e-' + digits);
    };
    /**
     * Verifies if the passed value is of type Function
     */
    /**
     * Verifies if the passed value is of type Function
     * @param {?} value
     * @return {?}
     */
    CommonUtil.isFunction = /**
     * Verifies if the passed value is of type Function
     * @param {?} value
     * @return {?}
     */
    function (value) {
        return typeof value === 'function';
    };
    /**
     * Creates a function that when called, actually calls the function parameter `fn` after a certain amount of time,
     * which is the value of `buffer` parameter. The created function then resolves the promise it returned and the same
     * promise is reused for all the calls that get buffered
     *
     * @param fn - Function to be debounced
     * @param scope - The function scope of the parameter `fn`
     * @param buffer - How long since the last call to the debounced function to wait before calling `fn`
     * @return A function that when called, will delay the calls to the `fn` that was passed in. That function will return
     * the same promise each time a call is made and buffered. This means that callers need to be sure to ignore previous
     * calls. This is not
     */
    /**
     * Creates a function that when called, actually calls the function parameter `fn` after a certain amount of time,
     * which is the value of `buffer` parameter. The created function then resolves the promise it returned and the same
     * promise is reused for all the calls that get buffered
     *
     * @template T
     * @param {?} fn - Function to be debounced
     * @param {?} scope - The function scope of the parameter `fn`
     * @param {?=} buffer - How long since the last call to the debounced function to wait before calling `fn`
     * @return {?} A function that when called, will delay the calls to the `fn` that was passed in. That function will return
     * the same promise each time a call is made and buffered. This means that callers need to be sure to ignore previous
     * calls. This is not
     */
    CommonUtil.createBufferedPromise = /**
     * Creates a function that when called, actually calls the function parameter `fn` after a certain amount of time,
     * which is the value of `buffer` parameter. The created function then resolves the promise it returned and the same
     * promise is reused for all the calls that get buffered
     *
     * @template T
     * @param {?} fn - Function to be debounced
     * @param {?} scope - The function scope of the parameter `fn`
     * @param {?=} buffer - How long since the last call to the debounced function to wait before calling `fn`
     * @return {?} A function that when called, will delay the calls to the `fn` that was passed in. That function will return
     * the same promise each time a call is made and buffered. This means that callers need to be sure to ignore previous
     * calls. This is not
     */
    function (fn, scope, buffer) {
        if (buffer === void 0) { buffer = 300; }
        /** @type {?} */
        var timerId;
        /** @type {?} */
        var pendingPromise = null;
        // tslint:disable-next-line:ban-types
        /** @type {?} */
        var resolver;
        // tslint:disable-next-line:only-arrow-functions
        return (/**
         * @return {?}
         */
        function () {
            if (!pendingPromise) {
                pendingPromise = new Promise((/**
                 * @param {?} resolve
                 * @return {?}
                 */
                function (resolve) {
                    resolver = resolve;
                }));
            }
            /** @type {?} */
            var callArgs = Array.from(arguments);
            if (timerId) {
                clearTimeout(timerId);
                timerId = null;
            }
            timerId = setTimeout((/**
             * @return {?}
             */
            function () {
                /** @type {?} */
                var retValue = fn.apply(scope, callArgs);
                resolver(retValue);
                pendingPromise = null;
                timerId = null;
            }), buffer);
            return pendingPromise;
        });
    };
    return CommonUtil;
}());
export { CommonUtil };
//# sourceMappingURL=data:application/json;base64, 