/**
 * This method accepts a number and returns a string representation
 * of the number formatted/abbreviated to the closest higher precision value.
 * @param {number} value - The value to be formatted
 * @param {number} precision - The default precision to be used for output
 * @param {boolean} prefixZero - Flag to prepend zero to the output if result is a single digit number
 * @returns {string} - The formatted/abbreviated string
 * @example <caption>Example usage of abbreviateNumber method.</caption>
 * // returns 12.1M
 * abbreviateNumber(12093093, 3);
 */
export const abbreviateNumber = (value = 0, precision = 1, prefixZero = true) => {
    const adjustedPrecision = isNaN(precision) ? 1 : precision;
    const adjustedValue = isNaN(value) ? 0 : parseFloat(`${value}`);
    const isNegativeValue = adjustedValue < 0;
    const absoluteValue = isNegativeValue ? Math.abs(adjustedValue) : value;
    let returnValue = absoluteValue.toFixed(adjustedPrecision);
    if (absoluteValue >= 1000) {
        const suffixes = ["", "K", "M", "B", "T", "P", "E", "Z", "Y"];
        const suffixNum = Math.floor((`${absoluteValue}`).length / 3);
        let shortValue = absoluteValue;
        for (let precisionCounter = adjustedPrecision; precisionCounter >= 1; precisionCounter--) {
            shortValue = parseFloat((suffixNum !== 0
                ? (absoluteValue / Math.pow(1000, suffixNum))
                : absoluteValue).toPrecision(precisionCounter));
            const dotLessShortValue = (`${shortValue}`).replace(/[^a-zA-Z 0-9]+/g, "");
            if (dotLessShortValue.length <= adjustedPrecision) {
                break;
            }
        }
        if (shortValue % 1 !== 0) {
            shortValue = parseFloat(shortValue.toFixed(adjustedPrecision));
        }
        returnValue = shortValue + suffixes[suffixNum];
    }
    else {
        returnValue = `${(prefixZero && absoluteValue < 10) ? "0" : ""}${parseFloat(returnValue)}`;
    }
    return `${isNegativeValue ? "-" : ""}${returnValue}`;
};
//# sourceMappingURL=index.js.map