@signumjs/util
Version:
Useful utilities and tools for building Signum Network applications
105 lines • 2.75 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Amount = exports.AmountFormats = exports.FormatCommaDecimal = exports.FormatDotDecimal = void 0;
const constants_1 = require("./constants");
const chainValue_1 = require("./chainValue");
exports.FormatDotDecimal = {
prefix: constants_1.CurrencySymbol + ' ',
decimalSeparator: '.',
groupSeparator: ',',
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: '',
fractionGroupSize: 0,
suffix: ''
};
exports.FormatCommaDecimal = {
prefix: constants_1.CurrencySymbol + ' ',
decimalSeparator: ',',
groupSeparator: '.',
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: '',
fractionGroupSize: 0,
suffix: ''
};
exports.AmountFormats = {
DotDecimal: exports.FormatDotDecimal,
CommaDecimal: exports.FormatCommaDecimal
};
class Amount {
_value;
constructor(planck) {
this._value = new chainValue_1.ChainValue(8).setAtomic(planck);
}
static CurrencySymbol() {
return constants_1.CurrencySymbol;
}
static Zero() {
return new Amount(0);
}
static fromPlanck(planck) {
return new Amount(planck);
}
static fromSigna(signa) {
const b = new Amount('0');
b.setSigna(typeof signa === 'number' ? signa.toString(10) : signa);
return b;
}
getRaw() {
return this._value.getRaw();
}
getPlanck() {
return this._value.getAtomic();
}
setPlanck(p) {
this._value.setAtomic(p);
return this;
}
getSigna() {
return this._value.getCompound();
}
setSigna(b) {
this._value.setCompound(b);
return this;
}
equals(amount) {
return this._value.equals(amount._value);
}
lessOrEqual(amount) {
return this._value.lessOrEqual(amount._value);
}
less(amount) {
return this._value.less(amount._value);
}
greaterOrEqual(amount) {
return this._value.greaterOrEqual(amount._value);
}
greater(amount) {
return this._value.greater(amount._value);
}
add(amount) {
this._value.add(amount._value);
return this;
}
subtract(amount) {
this._value.subtract(amount._value);
return this;
}
multiply(value) {
this._value.multiply(value);
return this;
}
divide(value) {
this._value.divide(value);
return this;
}
toString(format = exports.AmountFormats.DotDecimal) {
return this._value.toFormat(format.prefix, format);
}
clone() {
return Amount.fromPlanck(this.getPlanck());
}
}
exports.Amount = Amount;
//# sourceMappingURL=amount.js.map