UNPKG

tokenlon-sdk

Version:

imToken Tokenlon API for node

42 lines 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var utils_1 = require("@0xproject/utils"); var _ = require("lodash"); exports.isBigNumber = function (v) { return v instanceof utils_1.BigNumber || (v && v.isBigNumber === true) || (v && v._isBigNumber === true) || false; }; exports.isNumberLike = function (n) { // if use Number(n), 'toBN(-0xaa) will not pass this condition, will received only 0' // if you set params with empty string like ' ', it will return false, just like new BigNumber(' ') will throw error var num = parseFloat(n); return _.isNumber(num) && _.isFinite(num) && !_.isNaN(num); }; exports.toBN = function (value) { value = value || 0; if (exports.isBigNumber(value)) { return value; } if (!exports.isNumberLike(value)) { return new utils_1.BigNumber(0); } if (_.isString(value) && ((value).indexOf('0x') === 0 || (value).indexOf('-0x') === 0)) { return new utils_1.BigNumber((value).replace('0x', ''), 16); } return new utils_1.BigNumber((value).toString(10), 10); }; /** * Returns a string representing the value of this BigNumber in normal (fixed-point) notation rounded to dp decimal places using rounding mode rm. * @param {Number} n * @param {Number} dp [decimal places, 0 to 1e+9] * @param {Number} rm [rounding modes 0 to 6, Default value: 1 ROUND_DOWN ] http://mikemcl.github.io/bignumber.js/#round * @return {String} */ exports.toFixed = function (n, dp, rm) { if (dp === void 0) { dp = 4; } if (rm === void 0) { rm = 1; } return exports.toBN(n).toFixed(dp, rm); }; //# sourceMappingURL=math.js.map