import { toPercent, toSigned } from "@equilab/utils";
import BigNumber from "bignumber.js";
export const numberWithSeparator = (num, separator = ",") => {
    const number = num.toString().split(".");
    const integer = number[0];
    const fraction = number[1];
    return `${integer.replace(/\B(?=(\d{3})+(?!\d))/g, separator)}${fraction ? `.${fraction}` : ""}`;
};
export const numberWithCommas = (num) => numberWithSeparator(num);
export const safeToFixed = (value, precision, withSeparator, separator) => {
    if (typeof value === "undefined") {
        return "0.00";
    }
    else {
        const amount = parseFloat(value.toFixed(precision).replace(/^(\d+\.\d*?[1-9])0+$/, "$1")) * 1;
        if (withSeparator) {
            return numberWithSeparator(amount, separator);
        }
        return amount;
    }
};
export const safeToPercent = (value, precision) => {
    if (typeof value === "undefined") {
        return "-";
    }
    else if (value instanceof BigNumber) {
        return value.isNaN() || !value.isFinite()
            ? "-"
            : toPercent(value, precision);
    }
    else {
        return toPercent(new BigNumber(value), precision);
    }
};
export const safeToSigned = (value) => {
    if (typeof value === "undefined") {
        return "0.00";
    }
    else if (value instanceof BigNumber) {
        return toSigned(value.toNumber());
    }
    else {
        return toSigned(value);
    }
};
//# sourceMappingURL=format.js.map