eosplayer
Version:
eosplayer is the glue layer of eosjs, which is packaged based on eosjs and provides better usability for the application layer. It can be used on browsers already installed scatter or in Dapp wallets.
89 lines • 2.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Asset - asset type of eos
* @author kinghand@foxmail.com
*/
var Asset = /** @class */ (function () {
function Asset(_val, _sym, _decimal) {
if (_decimal === void 0) { _decimal = 4; }
this._val = _val;
this._sym = _sym;
this._decimal = _decimal;
}
Object.defineProperty(Asset.prototype, "val", {
/**
* get value
* @return {*}
*/
get: function () {
return this._val;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Asset.prototype, "sym", {
/**
* get symbol
* @return {*}
*/
get: function () {
return this._sym;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Asset.prototype, "decimal", {
/**
* get decimal
* @return {number|*}
*/
get: function () {
return this._decimal;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Asset.prototype, "valStr", {
/**
* Get String val without symbol
* @return {string | *}
*/
get: function () {
return this._val.toFixed(this.decimal);
},
enumerable: true,
configurable: true
});
/**
* Get string val with symbol, such as '1.0000 EOS'
* @return {string}
*/
Asset.prototype.toString = function () {
return this.valStr + " " + this.sym;
};
/**
* create a asset by asset string
* @param {string} assetStr
* @return {Asset}
*/
Asset.parse = function (assetStr) {
if (!assetStr)
return null;
assetStr = assetStr.trim();
var blankPos = assetStr.indexOf(' ');
if (blankPos < 0)
return null;
var strVal = assetStr.slice(0, blankPos);
var strSym = assetStr.slice(1 + blankPos);
if (!strVal || !strSym)
return null;
var decimalPos = assetStr.indexOf('.');
var decimal = decimalPos < 0 ? 0 : blankPos - decimalPos - 1;
var val = parseFloat(strVal);
return new Asset(val, strSym, decimal);
};
return Asset;
}());
exports.default = Asset;
//# sourceMappingURL=asset.js.map