@melonproject/token-math
Version:
A small helper library to do precision safe calculations
20 lines (19 loc) • 816 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const isQuantity_1 = __importDefault(require("../quantity/isQuantity"));
const toFixed_1 = __importDefault(require("../quantity/toFixed"));
const isPrice_1 = __importDefault(require("../price/isPrice"));
const toFixed_2 = __importDefault(require("../price/toFixed"));
const toFixed = (value, decimals) => {
if (isQuantity_1.default(value)) {
return toFixed_1.default(value, decimals);
}
if (isPrice_1.default(value)) {
return toFixed_2.default(value, decimals);
}
throw new TypeError(`"toFixed" not implemented for ${typeof value}`);
};
exports.default = toFixed;