WXL
3 天以前 4d9da000fbe74d344e0e4580b138e79d4ad98ede
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toPrice = void 0;
const decimal_js_1 = __importDefault(require("decimal.js"));
/**
 *
 * @param price formatted as `<amount><denom>`
 */
function toPrice(price) {
    if (typeof price === "string") {
        const matchResult = price.match(/^([0-9.]+)([a-z][a-z0-9]*)$/i);
        if (!matchResult) {
            throw new Error("Invalid price string. Please check if the format is `<amount><denom>`");
        }
        const [, amount, denom] = matchResult;
        return {
            amount: new decimal_js_1.default(amount),
            denom,
        };
    }
    return price;
}
exports.toPrice = toPrice;
//# sourceMappingURL=price.js.map