"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    NumberReg: function() {
        return NumberReg;
    },
    parseNumber: function() {
        return parseNumber;
    }
});
const _utils = require("@orderly.network/utils");
const parseNumber = (value, options = {})=>{
    let { rule, precision, tick, truncate, padding, abs } = options;
    if (Number.isNaN(value)) {
        return "--";
    }
    const dp = typeof precision !== "undefined" ? precision : tick ? (0, _utils.getPrecisionByNumber)(tick) : 2;
    if (rule === "human") {
        return (0, _utils.numberToHumanStyle)(typeof value === "number" ? value : Number(value), dp);
    }
    let d = new _utils.Decimal(value);
    if (abs) {
        d = d.abs();
    }
    if (rule === "percentages") {
        return `${d.mul(100).toFixed(2)}%`;
    }
    let truncatedNum;
    if (truncate === "round") {
        if (padding) {
            truncatedNum = d.toFixed(dp, _utils.Decimal.ROUND_HALF_EVEN);
        } else {
            truncatedNum = d.todp(dp, _utils.Decimal.ROUND_HALF_EVEN).toString();
        }
    } else {
        if (padding) {
            truncatedNum = d.toFixed(dp);
        } else {
            truncatedNum = d.todp(dp).toString();
        }
    }
    if (rule === "price") {
        return (0, _utils.commify)(truncatedNum);
    }
    if (truncatedNum?.includes("e")) {
        // If dp is omitted, the return value will be unrounded and in normal notation.
        // https://mikemcl.github.io/decimal.js/#toFixed
        return new _utils.Decimal(truncatedNum)?.toFixed();
    }
    return truncatedNum;
};
const NumberReg = /^([0-9]{1,}[.]?[0-9]*)/;

//# sourceMappingURL=num.js.map