/* eslint-disable jsdoc/require-description-complete-sentence */ /**
 * Checks if the passed value is numeric one. For example these values (passed as string or number)
 * are considered as numeric values:
 *  - 0.001
 *  - .001
 *  - 10000
 *  - 1e+26
 *  - 22e-26
 *  - .45e+26
 *  - 0xabcdef (hex)
 *  - 0x1 (hex)
 *
 * these values are not considered as numeric:
 *  - - 1000
 *  - 100 000
 *
 * @param {*} value The value to check.
 * @param {string[]} additionalDelimiters An additional delimiters to be used while checking the numeric value.
 * @returns {boolean}
 */ "use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get clamp () {
        return clamp;
    },
    get getParsedNumber () {
        return getParsedNumber;
    },
    get isCommaThousandsGroupedInteger () {
        return isCommaThousandsGroupedInteger;
    },
    get isNumeric () {
        return isNumeric;
    },
    get isNumericLike () {
        return isNumericLike;
    },
    get isUnsignedNumber () {
        return isUnsignedNumber;
    },
    get rangeEach () {
        return rangeEach;
    },
    get rangeEachReverse () {
        return rangeEachReverse;
    },
    get valueAccordingPercent () {
        return valueAccordingPercent;
    }
});
function isNumeric(value, additionalDelimiters = []) {
    const type = typeof value;
    if (type === 'number') {
        return !isNaN(value) && isFinite(value);
    } else if (type === 'string') {
        if (value.length === 0) {
            return false;
        } else if (value.length === 1) {
            return /\d/.test(value);
        }
        const delimiter = Array.from(new Set([
            '.',
            ...additionalDelimiters
        ])).map((d)=>`\\${d}`).join('|');
        return new RegExp(`^[+-]?(((${delimiter})?\\d+((${delimiter})\\d+)?(e[+-]?\\d+)?)|(0x[a-f\\d]+))$`, 'i').test(value.trim());
    } else if (type === 'object') {
        return !!value && typeof value.valueOf() === 'number' && !(value instanceof Date);
    }
    return false;
}
function isNumericLike(value) {
    return isNumeric(value, [
        ','
    ]);
}
function isCommaThousandsGroupedInteger(value, decimalSeparator) {
    if (decimalSeparator !== '.' || typeof value !== 'string') {
        return false;
    }
    return /^[+-]?[1-9]\d{0,2}(,\d{3})+$/.test(value.trim());
}
function rangeEach(rangeFrom, rangeTo, iteratee) {
    let index = -1;
    if (typeof rangeTo === 'function') {
        iteratee = rangeTo;
        rangeTo = rangeFrom;
    } else {
        index = rangeFrom - 1;
    }
    /* eslint-disable-next-line no-plusplus */ while(++index <= rangeTo){
        if (iteratee(index) === false) {
            break;
        }
    }
}
function rangeEachReverse(rangeFrom, rangeTo, iteratee) {
    let index = rangeFrom + 1;
    if (typeof rangeTo === 'function') {
        iteratee = rangeTo;
        rangeTo = 0;
    }
    /* eslint-disable-next-line no-plusplus */ while(--index >= rangeTo){
        if (iteratee(index) === false) {
            break;
        }
    }
}
function valueAccordingPercent(value, percent) {
    percent = parseInt(percent.toString().replace('%', ''), 10);
    percent = isNaN(percent) ? 0 : percent;
    return parseInt(value * percent / 100, 10);
}
function clamp(value, minValue, maxValue) {
    if (Math.min(value, minValue) === value) {
        return minValue;
    } else if (Math.max(value, maxValue) === value) {
        return maxValue;
    }
    return value;
}
function getParsedNumber(numericData, options = {}) {
    const { decimalSeparator } = options;
    const normalizedNumericData = numericData.trim();
    if (isCommaThousandsGroupedInteger(numericData, decimalSeparator)) {
        return parseFloat(normalizedNumericData.replace(/,/g, ''));
    }
    // Unifying "float like" string. Change from value with comma determiner to value with dot determiner,
    // for example from `450,65` to `450.65`.
    const unifiedNumericData = normalizedNumericData.replace(',', '.');
    if (isNaN(parseFloat(unifiedNumericData)) === false) {
        return parseFloat(unifiedNumericData);
    }
    return null;
}
function isUnsignedNumber(value) {
    return Number.isInteger(value) && value >= 0;
}
