@glif/filecoin-number
Advanced tools
Comparing version 2.0.53 to 2.0.54
@@ -16,7 +16,6 @@ /// <reference types="node" /> | ||
export declare class FilecoinNumber extends BigNumber { | ||
static readonly Zero: FilecoinNumber; | ||
static readonly TZero: FilecoinNumber; | ||
private static zeroCtMap; | ||
private static zeroCtUnitMap; | ||
private readonly _ct?; | ||
private readonly _unit?; | ||
readonly unit: string; | ||
constructor(value: BigNumber.Value, denom: FilecoinDenomination, coinType?: CoinType, unit?: string); | ||
@@ -29,6 +28,14 @@ /** | ||
/** | ||
* Return zero fil instance for CoinType | ||
* Returns a static zero fil instance for the CoinType and unit | ||
*/ | ||
static zero(coinType: CoinType): FilecoinNumber; | ||
static zero(coinType?: CoinType, unit?: string): FilecoinNumber; | ||
/** | ||
* Returns the unit derived from constructor params | ||
*/ | ||
get unit(): string; | ||
/** | ||
* Returns the denominator specific unit (omits 't' if adding other prefix) | ||
*/ | ||
getDenomUnit(denom: FilecoinDenomination): string; | ||
/** | ||
* Expresses this FilecoinNumber as a FIL string | ||
@@ -35,0 +42,0 @@ */ |
@@ -24,3 +24,3 @@ "use strict"; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _defineProperty4 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -31,5 +31,7 @@ var _bignumber = require("bignumber.js"); | ||
var _defineProperty2, _defineProperty3; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty4["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
@@ -86,2 +88,5 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } | ||
// Stores static FilecoinNumber(0, 'fil') instances per CoinType | ||
// Stores static FilecoinNumber(0, 'fil') instances per CoinType and unit | ||
// Constructor params | ||
function FilecoinNumber(value, denom, coinType, unit) { | ||
@@ -92,8 +97,6 @@ var _this; | ||
_this = _super.call(this, toBigNumberValue(value, denom)); | ||
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_ct", void 0); | ||
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_unit", void 0); | ||
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "unit", void 0); | ||
(0, _defineProperty4["default"])((0, _assertThisInitialized2["default"])(_this), "_ct", void 0); | ||
(0, _defineProperty4["default"])((0, _assertThisInitialized2["default"])(_this), "_unit", void 0); | ||
_this._ct = coinType; | ||
_this._unit = unit; | ||
_this.unit = unit !== null && unit !== void 0 ? unit : "".concat(coinType === CoinType.TEST ? 't' : '', "FIL"); | ||
return _this; | ||
@@ -108,7 +111,19 @@ } | ||
(0, _createClass2["default"])(FilecoinNumber, [{ | ||
key: "toFil", | ||
key: "getDenomUnit", | ||
/** | ||
* Returns the denominator specific unit (omits 't' if adding other prefix) | ||
*/ | ||
value: function getDenomUnit(denom) { | ||
var _this$_unit; | ||
var unitDenom = denom.replace(/fil$/, ''); | ||
return unitDenom ? "".concat(unitDenom).concat((_this$_unit = this._unit) !== null && _this$_unit !== void 0 ? _this$_unit : 'FIL') : this.unit; | ||
} | ||
/** | ||
* Expresses this FilecoinNumber as a FIL string | ||
*/ | ||
}, { | ||
key: "toFil", | ||
value: function toFil() { | ||
@@ -295,2 +310,13 @@ return this.toString(); | ||
} | ||
}, { | ||
key: "unit", | ||
/** | ||
* Returns the unit derived from constructor params | ||
*/ | ||
get: function get() { | ||
var _this$_unit2; | ||
return (_this$_unit2 = this._unit) !== null && _this$_unit2 !== void 0 ? _this$_unit2 : "".concat(this._ct === CoinType.TEST ? 't' : '', "FIL"); | ||
} | ||
}], [{ | ||
@@ -302,3 +328,3 @@ key: "isFilecoinNumber", | ||
/** | ||
* Return zero fil instance for CoinType | ||
* Returns a static zero fil instance for the CoinType and unit | ||
*/ | ||
@@ -308,13 +334,7 @@ | ||
key: "zero", | ||
value: function zero(coinType) { | ||
switch (coinType) { | ||
case CoinType.MAIN: | ||
return FilecoinNumber.Zero; | ||
case CoinType.TEST: | ||
return FilecoinNumber.TZero; | ||
default: | ||
throw new Error("Unsupported CoinType: ".concat(coinType)); | ||
} | ||
value: function zero(coinType, unit) { | ||
var ct = coinType !== null && coinType !== void 0 ? coinType : CoinType.MAIN; | ||
if (unit === undefined) return this.zeroCtMap[ct]; | ||
if (this.zeroCtUnitMap[ct][unit] === undefined) this.zeroCtUnitMap[ct][unit] = new FilecoinNumber(0, 'fil', ct, unit); | ||
return this.zeroCtUnitMap[ct][unit]; | ||
} | ||
@@ -326,4 +346,4 @@ }]); | ||
exports.FilecoinNumber = FilecoinNumber; | ||
(0, _defineProperty2["default"])(FilecoinNumber, "Zero", new FilecoinNumber(0, 'fil', CoinType.MAIN)); | ||
(0, _defineProperty2["default"])(FilecoinNumber, "TZero", new FilecoinNumber(0, 'fil', CoinType.TEST)); | ||
(0, _defineProperty4["default"])(FilecoinNumber, "zeroCtMap", (_defineProperty2 = {}, (0, _defineProperty4["default"])(_defineProperty2, CoinType.MAIN, new FilecoinNumber(0, 'fil', CoinType.MAIN)), (0, _defineProperty4["default"])(_defineProperty2, CoinType.TEST, new FilecoinNumber(0, 'fil', CoinType.TEST)), _defineProperty2)); | ||
(0, _defineProperty4["default"])(FilecoinNumber, "zeroCtUnitMap", (_defineProperty3 = {}, (0, _defineProperty4["default"])(_defineProperty3, CoinType.MAIN, {}), (0, _defineProperty4["default"])(_defineProperty3, CoinType.TEST, {}), _defineProperty3)); | ||
//# sourceMappingURL=FilecoinNumber.js.map |
@@ -10,2 +10,4 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
var _defineProperty2, _defineProperty3; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
@@ -64,2 +66,5 @@ | ||
// Stores static FilecoinNumber(0, 'fil') instances per CoinType | ||
// Stores static FilecoinNumber(0, 'fil') instances per CoinType and unit | ||
// Constructor params | ||
function FilecoinNumber(value, denom, coinType, unit) { | ||
@@ -76,7 +81,4 @@ var _this; | ||
_defineProperty(_assertThisInitialized(_this), "unit", void 0); | ||
_this._ct = coinType; | ||
_this._unit = unit; | ||
_this.unit = unit !== null && unit !== void 0 ? unit : "".concat(coinType === CoinType.TEST ? 't' : '', "FIL"); | ||
return _this; | ||
@@ -91,7 +93,19 @@ } | ||
_createClass(FilecoinNumber, [{ | ||
key: "toFil", | ||
key: "getDenomUnit", | ||
/** | ||
* Returns the denominator specific unit (omits 't' if adding other prefix) | ||
*/ | ||
value: function getDenomUnit(denom) { | ||
var _this$_unit; | ||
var unitDenom = denom.replace(/fil$/, ''); | ||
return unitDenom ? "".concat(unitDenom).concat((_this$_unit = this._unit) !== null && _this$_unit !== void 0 ? _this$_unit : 'FIL') : this.unit; | ||
} | ||
/** | ||
* Expresses this FilecoinNumber as a FIL string | ||
*/ | ||
}, { | ||
key: "toFil", | ||
value: function toFil() { | ||
@@ -278,2 +292,13 @@ return this.toString(); | ||
} | ||
}, { | ||
key: "unit", | ||
/** | ||
* Returns the unit derived from constructor params | ||
*/ | ||
get: function get() { | ||
var _this$_unit2; | ||
return (_this$_unit2 = this._unit) !== null && _this$_unit2 !== void 0 ? _this$_unit2 : "".concat(this._ct === CoinType.TEST ? 't' : '', "FIL"); | ||
} | ||
}], [{ | ||
@@ -285,3 +310,3 @@ key: "isFilecoinNumber", | ||
/** | ||
* Return zero fil instance for CoinType | ||
* Returns a static zero fil instance for the CoinType and unit | ||
*/ | ||
@@ -291,13 +316,7 @@ | ||
key: "zero", | ||
value: function zero(coinType) { | ||
switch (coinType) { | ||
case CoinType.MAIN: | ||
return FilecoinNumber.Zero; | ||
case CoinType.TEST: | ||
return FilecoinNumber.TZero; | ||
default: | ||
throw new Error("Unsupported CoinType: ".concat(coinType)); | ||
} | ||
value: function zero(coinType, unit) { | ||
var ct = coinType !== null && coinType !== void 0 ? coinType : CoinType.MAIN; | ||
if (unit === undefined) return this.zeroCtMap[ct]; | ||
if (this.zeroCtUnitMap[ct][unit] === undefined) this.zeroCtUnitMap[ct][unit] = new FilecoinNumber(0, 'fil', ct, unit); | ||
return this.zeroCtUnitMap[ct][unit]; | ||
} | ||
@@ -309,5 +328,5 @@ }]); | ||
_defineProperty(FilecoinNumber, "Zero", new FilecoinNumber(0, 'fil', CoinType.MAIN)); | ||
_defineProperty(FilecoinNumber, "zeroCtMap", (_defineProperty2 = {}, _defineProperty(_defineProperty2, CoinType.MAIN, new FilecoinNumber(0, 'fil', CoinType.MAIN)), _defineProperty(_defineProperty2, CoinType.TEST, new FilecoinNumber(0, 'fil', CoinType.TEST)), _defineProperty2)); | ||
_defineProperty(FilecoinNumber, "TZero", new FilecoinNumber(0, 'fil', CoinType.TEST)); | ||
_defineProperty(FilecoinNumber, "zeroCtUnitMap", (_defineProperty3 = {}, _defineProperty(_defineProperty3, CoinType.MAIN, {}), _defineProperty(_defineProperty3, CoinType.TEST, {}), _defineProperty3)); | ||
//# sourceMappingURL=FilecoinNumber.js.map |
@@ -48,2 +48,5 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
export class FilecoinNumber extends BigNumber { | ||
// Stores static FilecoinNumber(0, 'fil') instances per CoinType | ||
// Stores static FilecoinNumber(0, 'fil') instances per CoinType and unit | ||
// Constructor params | ||
constructor(value, denom, coinType, unit) { | ||
@@ -56,7 +59,4 @@ super(toBigNumberValue(value, denom)); | ||
_defineProperty(this, "unit", void 0); | ||
this._ct = coinType; | ||
this._unit = unit; | ||
this.unit = unit ?? `${coinType === CoinType.TEST ? 't' : ''}FIL`; | ||
} | ||
@@ -73,19 +73,30 @@ /** | ||
/** | ||
* Return zero fil instance for CoinType | ||
* Returns a static zero fil instance for the CoinType and unit | ||
*/ | ||
static zero(coinType) { | ||
switch (coinType) { | ||
case CoinType.MAIN: | ||
return FilecoinNumber.Zero; | ||
static zero(coinType, unit) { | ||
const ct = coinType ?? CoinType.MAIN; | ||
if (unit === undefined) return this.zeroCtMap[ct]; | ||
if (this.zeroCtUnitMap[ct][unit] === undefined) this.zeroCtUnitMap[ct][unit] = new FilecoinNumber(0, 'fil', ct, unit); | ||
return this.zeroCtUnitMap[ct][unit]; | ||
} | ||
/** | ||
* Returns the unit derived from constructor params | ||
*/ | ||
case CoinType.TEST: | ||
return FilecoinNumber.TZero; | ||
default: | ||
throw new Error(`Unsupported CoinType: ${coinType}`); | ||
} | ||
get unit() { | ||
return this._unit ?? `${this._ct === CoinType.TEST ? 't' : ''}FIL`; | ||
} | ||
/** | ||
* Returns the denominator specific unit (omits 't' if adding other prefix) | ||
*/ | ||
getDenomUnit(denom) { | ||
const unitDenom = denom.replace(/fil$/, ''); | ||
return unitDenom ? `${unitDenom}${this._unit ?? 'FIL'}` : this.unit; | ||
} | ||
/** | ||
* Expresses this FilecoinNumber as a FIL string | ||
@@ -262,5 +273,11 @@ */ | ||
_defineProperty(FilecoinNumber, "Zero", new FilecoinNumber(0, 'fil', CoinType.MAIN)); | ||
_defineProperty(FilecoinNumber, "zeroCtMap", { | ||
[CoinType.MAIN]: new FilecoinNumber(0, 'fil', CoinType.MAIN), | ||
[CoinType.TEST]: new FilecoinNumber(0, 'fil', CoinType.TEST) | ||
}); | ||
_defineProperty(FilecoinNumber, "TZero", new FilecoinNumber(0, 'fil', CoinType.TEST)); | ||
_defineProperty(FilecoinNumber, "zeroCtUnitMap", { | ||
[CoinType.MAIN]: {}, | ||
[CoinType.TEST]: {} | ||
}); | ||
//# sourceMappingURL=FilecoinNumber.js.map |
{ | ||
"name": "@glif/filecoin-number", | ||
"version": "2.0.53", | ||
"version": "2.0.54", | ||
"description": "a javascript package to handle Filecoin numbers like Fil and AttoFil", | ||
@@ -50,3 +50,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "32a220004fd620dd2981666c00f5779ef8dd6417" | ||
"gitHead": "d53070e8a8dde9857461304851d674774f875521" | ||
} |
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
147848
1318