@glif/filecoin-number
Advanced tools
Comparing version 3.0.2 to 3.0.3
@@ -77,2 +77,6 @@ /// <reference types="node" /> | ||
/** | ||
* Expresses this FilecoinNumber as a formatted AttoFIL string | ||
*/ | ||
formatAttoFil(options?: Pick<FilecoinFormatOptions, 'addUnit' | 'prefix'>): string; | ||
/** | ||
* Expresses this FilecoinNumber as a balance string | ||
@@ -79,0 +83,0 @@ */ |
@@ -152,2 +152,18 @@ "use strict"; | ||
/** | ||
* Expresses this FilecoinNumber as a formatted AttoFIL string | ||
*/ | ||
}, { | ||
key: "formatAttoFil", | ||
value: function formatAttoFil(options) { | ||
var _options$addUnit, _options$prefix; | ||
var addUnit = (_options$addUnit = options === null || options === void 0 ? void 0 : options.addUnit) !== null && _options$addUnit !== void 0 ? _options$addUnit : true; | ||
return this.shiftedBy(18).toFormat(0, _bignumber.BigNumber.ROUND_DOWN, { | ||
groupSeparator: ',', | ||
groupSize: 3, | ||
suffix: addUnit ? " ".concat(this.getDenomUnit('attofil')) : '', | ||
prefix: (_options$prefix = options === null || options === void 0 ? void 0 : options.prefix) !== null && _options$prefix !== void 0 ? _options$prefix : '' | ||
}); | ||
} | ||
/** | ||
* Expresses this FilecoinNumber as a balance string | ||
@@ -158,3 +174,3 @@ */ | ||
value: function formatBalance(options) { | ||
var _options$truncate, _options$decimals, _options$padZeros, _options$addUnit; | ||
var _options$truncate, _options$decimals, _options$padZeros, _options$addUnit2, _options$prefix2; | ||
var truncate = (_options$truncate = options === null || options === void 0 ? void 0 : options.truncate) !== null && _options$truncate !== void 0 ? _options$truncate : true; | ||
@@ -164,4 +180,3 @@ var round = (options === null || options === void 0 ? void 0 : options.decimals) !== null; | ||
var padZeros = (_options$padZeros = options === null || options === void 0 ? void 0 : options.padZeros) !== null && _options$padZeros !== void 0 ? _options$padZeros : false; | ||
var addUnit = (_options$addUnit = options === null || options === void 0 ? void 0 : options.addUnit) !== null && _options$addUnit !== void 0 ? _options$addUnit : true; | ||
var prefix = options === null || options === void 0 ? void 0 : options.prefix; | ||
var addUnit = (_options$addUnit2 = options === null || options === void 0 ? void 0 : options.addUnit) !== null && _options$addUnit2 !== void 0 ? _options$addUnit2 : true; | ||
var toFormat = function toFormat(value, format) { | ||
@@ -177,3 +192,3 @@ return padZeros ? value.toFormat(decimals, _bignumber.BigNumber.ROUND_DOWN, format) : value.toFormat(format); | ||
suffix: addUnit ? " ".concat(this.displayUnit) : '', | ||
prefix: prefix | ||
prefix: (_options$prefix2 = options === null || options === void 0 ? void 0 : options.prefix) !== null && _options$prefix2 !== void 0 ? _options$prefix2 : '' | ||
}; | ||
@@ -194,5 +209,5 @@ | ||
// "< 0" for negative and "> 0" for positive values | ||
var _prefix = isNegative ? '< ' : '> '; | ||
var prefix = "".concat(isNegative ? '<' : '>', " ").concat(format.prefix); | ||
return toFormat(rounded, _objectSpread(_objectSpread({}, format), {}, { | ||
prefix: _prefix | ||
prefix: prefix | ||
})); | ||
@@ -202,6 +217,6 @@ } else { | ||
// "> -0.01" for negative and "< 0.01" for positive values | ||
var _prefix2 = isNegative ? '> ' : '< '; | ||
var _prefix = "".concat(isNegative ? '>' : '<', " ").concat(format.prefix); | ||
var roundedUp = this.dp(decimals, _bignumber.BigNumber.ROUND_UP); | ||
return toFormat(roundedUp, _objectSpread(_objectSpread({}, format), {}, { | ||
prefix: _prefix2 | ||
prefix: _prefix | ||
})); | ||
@@ -208,0 +223,0 @@ } |
@@ -148,2 +148,18 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
/** | ||
* Expresses this FilecoinNumber as a formatted AttoFIL string | ||
*/ | ||
}, { | ||
key: "formatAttoFil", | ||
value: function formatAttoFil(options) { | ||
var _options$addUnit, _options$prefix; | ||
var addUnit = (_options$addUnit = options === null || options === void 0 ? void 0 : options.addUnit) !== null && _options$addUnit !== void 0 ? _options$addUnit : true; | ||
return this.shiftedBy(18).toFormat(0, BigNumber.ROUND_DOWN, { | ||
groupSeparator: ',', | ||
groupSize: 3, | ||
suffix: addUnit ? " ".concat(this.getDenomUnit('attofil')) : '', | ||
prefix: (_options$prefix = options === null || options === void 0 ? void 0 : options.prefix) !== null && _options$prefix !== void 0 ? _options$prefix : '' | ||
}); | ||
} | ||
/** | ||
* Expresses this FilecoinNumber as a balance string | ||
@@ -154,3 +170,3 @@ */ | ||
value: function formatBalance(options) { | ||
var _options$truncate, _options$decimals, _options$padZeros, _options$addUnit; | ||
var _options$truncate, _options$decimals, _options$padZeros, _options$addUnit2, _options$prefix2; | ||
var truncate = (_options$truncate = options === null || options === void 0 ? void 0 : options.truncate) !== null && _options$truncate !== void 0 ? _options$truncate : true; | ||
@@ -160,4 +176,3 @@ var round = (options === null || options === void 0 ? void 0 : options.decimals) !== null; | ||
var padZeros = (_options$padZeros = options === null || options === void 0 ? void 0 : options.padZeros) !== null && _options$padZeros !== void 0 ? _options$padZeros : false; | ||
var addUnit = (_options$addUnit = options === null || options === void 0 ? void 0 : options.addUnit) !== null && _options$addUnit !== void 0 ? _options$addUnit : true; | ||
var prefix = options === null || options === void 0 ? void 0 : options.prefix; | ||
var addUnit = (_options$addUnit2 = options === null || options === void 0 ? void 0 : options.addUnit) !== null && _options$addUnit2 !== void 0 ? _options$addUnit2 : true; | ||
var toFormat = function toFormat(value, format) { | ||
@@ -173,3 +188,3 @@ return padZeros ? value.toFormat(decimals, BigNumber.ROUND_DOWN, format) : value.toFormat(format); | ||
suffix: addUnit ? " ".concat(this.displayUnit) : '', | ||
prefix: prefix | ||
prefix: (_options$prefix2 = options === null || options === void 0 ? void 0 : options.prefix) !== null && _options$prefix2 !== void 0 ? _options$prefix2 : '' | ||
}; | ||
@@ -190,5 +205,5 @@ | ||
// "< 0" for negative and "> 0" for positive values | ||
var _prefix = isNegative ? '< ' : '> '; | ||
var prefix = "".concat(isNegative ? '<' : '>', " ").concat(format.prefix); | ||
return toFormat(rounded, _objectSpread(_objectSpread({}, format), {}, { | ||
prefix: _prefix | ||
prefix: prefix | ||
})); | ||
@@ -198,6 +213,6 @@ } else { | ||
// "> -0.01" for negative and "< 0.01" for positive values | ||
var _prefix2 = isNegative ? '> ' : '< '; | ||
var _prefix = "".concat(isNegative ? '>' : '<', " ").concat(format.prefix); | ||
var roundedUp = this.dp(decimals, BigNumber.ROUND_UP); | ||
return toFormat(roundedUp, _objectSpread(_objectSpread({}, format), {}, { | ||
prefix: _prefix2 | ||
prefix: _prefix | ||
})); | ||
@@ -204,0 +219,0 @@ } |
@@ -142,2 +142,15 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
/** | ||
* Expresses this FilecoinNumber as a formatted AttoFIL string | ||
*/ | ||
formatAttoFil(options) { | ||
const addUnit = (options === null || options === void 0 ? void 0 : options.addUnit) ?? true; | ||
return this.shiftedBy(18).toFormat(0, BigNumber.ROUND_DOWN, { | ||
groupSeparator: ',', | ||
groupSize: 3, | ||
suffix: addUnit ? ` ${this.getDenomUnit('attofil')}` : '', | ||
prefix: (options === null || options === void 0 ? void 0 : options.prefix) ?? '' | ||
}); | ||
} | ||
/** | ||
* Expresses this FilecoinNumber as a balance string | ||
@@ -151,3 +164,2 @@ */ | ||
const addUnit = (options === null || options === void 0 ? void 0 : options.addUnit) ?? true; | ||
const prefix = options === null || options === void 0 ? void 0 : options.prefix; | ||
const toFormat = (value, format) => padZeros ? value.toFormat(decimals, BigNumber.ROUND_DOWN, format) : value.toFormat(format); | ||
@@ -161,3 +173,3 @@ | ||
suffix: addUnit ? ` ${this.displayUnit}` : '', | ||
prefix | ||
prefix: (options === null || options === void 0 ? void 0 : options.prefix) ?? '' | ||
}; | ||
@@ -178,3 +190,3 @@ | ||
// "< 0" for negative and "> 0" for positive values | ||
const prefix = isNegative ? '< ' : '> '; | ||
const prefix = `${isNegative ? '<' : '>'} ${format.prefix}`; | ||
return toFormat(rounded, _objectSpread(_objectSpread({}, format), {}, { | ||
@@ -186,3 +198,3 @@ prefix | ||
// "> -0.01" for negative and "< 0.01" for positive values | ||
const prefix = isNegative ? '> ' : '< '; | ||
const prefix = `${isNegative ? '>' : '<'} ${format.prefix}`; | ||
const roundedUp = this.dp(decimals, BigNumber.ROUND_UP); | ||
@@ -189,0 +201,0 @@ return toFormat(roundedUp, _objectSpread(_objectSpread({}, format), {}, { |
{ | ||
"name": "@glif/filecoin-number", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "a javascript package to handle Filecoin numbers like Fil and AttoFil", | ||
@@ -50,3 +50,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "1a1ba285434fd3d37592f1955a9225a53287ecc7" | ||
"gitHead": "da48b898479f691894088c499a9e3976cc554ed2" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
220935
1903