UNPKG

libnexa-ts

Version:

A pure and powerful Nexa SDK library.

43 lines 1.54 kB
import { BigNumberish } from '../common/types'; export declare enum UnitType { MEX = 8, KEX = 5, NEXA = 2 } /** * Utility for handling and converting nexa units. * You can consult for different representation of a unit using it's * {format} method or the fixed unit methods like {parse}. * * @example * ```ts * let nex = UnitUtils.formatNEXA(546); // "5.46" * let sats = UnitUtils.parseNEXA("5.46"); // 546n * let mex = UnitUtils.formatUnits(100000000, UnitType.MEX) // "1.00000000"; * let units = UnitUtils.parseUnits('1.0', 5); // 100000n * ``` */ export default class UnitUtils { /** * Converts `value` into a decimal string, assuming `unit` decimal * places. The `unit` may be the number of decimal places or the enum of * a unit (e.g. ``UnitType.MEX`` for 8 decimal places). * */ static formatUnits(value: BigNumberish, unit?: UnitType | number): string; /** * Converts the decimal string `value` to a BigInt, assuming * `unit` decimal places. The `unit` may the number of decimal places * or the name of a unit (e.g. ``UnitType.KEX`` for 5 decimal places). */ static parseUnits(value: string, unit?: UnitType | number): bigint; /** * Converts `value` into a decimal string using 2 decimal places. */ static formatNEXA(sats: BigNumberish): string; /** * Converts the decimal string `NEXA` to a BigInt, using 2 decimal places. */ static parseNEXA(nexa: string): bigint; } //# sourceMappingURL=unit.utils.d.ts.map