@exodus/currency
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -8,3 +8,3 @@ "use strict"; | ||
var _bignumber = _interopRequireDefault(require("bignumber.js")); | ||
var _bigRational = _interopRequireDefault(require("big-rational")); | ||
@@ -21,6 +21,2 @@ var _isNumberUnit2 = _interopRequireDefault(require("./is-number-unit")); | ||
_bignumber.default.config({ | ||
DECIMAL_PLACES: 20 | ||
}); | ||
class NumberUnit { | ||
@@ -44,3 +40,3 @@ static create(num, unit) { | ||
this._number = new _bignumber.default(num); | ||
this._number = (0, _bigRational.default)(num); | ||
this.unit = unit; | ||
@@ -61,3 +57,3 @@ this.unitType = unit.unitType; | ||
const sumBase = base._number.plus(thisBase._number); | ||
const sumBase = base._number.add(thisBase._number); | ||
@@ -79,3 +75,3 @@ return new NumberUnit(sumBase, this.baseUnit).to(this.unit); | ||
let thisBase = this.toBase(); | ||
return base._number.eq(thisBase._number); | ||
return base._number.equals(thisBase._number); | ||
} | ||
@@ -92,3 +88,3 @@ | ||
let thisBase = this.toBase(); | ||
return thisBase._number.gte(base._number); | ||
return thisBase._number.greaterOrEquals(base._number); | ||
} | ||
@@ -105,3 +101,3 @@ | ||
let thisBase = this.toBase(); | ||
return thisBase._number.lte(base._number); | ||
return thisBase._number.lesserOrEquals(base._number); | ||
} | ||
@@ -111,3 +107,3 @@ | ||
const base = this.toBase(); | ||
base._number = base._number.times(num); | ||
base._number = base._number.multiply(num); | ||
return base.to(this.unit); | ||
@@ -129,10 +125,23 @@ } | ||
toFixed(x, rm) { | ||
let crm; | ||
if (rm === 'floor') crm = 3; | ||
if (rm === 'ceil') crm = 2; | ||
return new NumberUnit(this._number.toFixed(x, crm), this.unit); | ||
const pow = Math.pow(10, x); | ||
let num = this._number; | ||
switch (rm) { | ||
case 'floor': | ||
num = num.multiply(pow).floor().divide(pow); | ||
break; | ||
case 'ceil': | ||
num = num.multiply(pow).ceil().divide(pow); | ||
break; | ||
default: | ||
num = num.multiply(pow).round().divide(pow); | ||
} | ||
return new NumberUnit(num.toDecimal(x), this.unit); | ||
} | ||
negate() { | ||
return new NumberUnit(this._number.negated(), this.unit); | ||
return new NumberUnit(this._number.negate(), this.unit); | ||
} | ||
@@ -144,3 +153,3 @@ | ||
let sumBase = thisBase._number.minus(base._number); | ||
let sumBase = thisBase._number.subtract(base._number); | ||
@@ -179,3 +188,3 @@ return new NumberUnit(sumBase, this.baseUnit).to(this.unit); | ||
let newNumber = normalizeNum._number.times(conversionUnit.toValue).div(conversionUnit.fromValue); | ||
let newNumber = normalizeNum._number.times(conversionUnit.toValue).divide(conversionUnit.fromValue); | ||
@@ -189,3 +198,3 @@ return new NumberUnit(newNumber, conversionUnit.to.unitType[conversionUnit.toUnit]); | ||
let newNumber = base._number.div(unit.multiplier); | ||
let newNumber = base._number.divide(unit.multiplier); | ||
@@ -198,3 +207,3 @@ return new NumberUnit(newNumber, unit); | ||
return { | ||
value: this._number.toString(), | ||
value: this.toNumberString(), | ||
unit: this.unitName, | ||
@@ -207,7 +216,7 @@ unitType: this.unitType.toString(), | ||
toNumber() { | ||
return this._number.toNumber(); | ||
return this._number.valueOf(); | ||
} | ||
toNumberString() { | ||
return this._number.toString(); | ||
return this._number.toDecimal(20); | ||
} | ||
@@ -220,3 +229,3 @@ | ||
if (!format) { | ||
return this._number.toString() + (unit ? ' ' + this.unitName : ''); | ||
return this.toNumberString() + (unit ? ' ' + this.unitName : ''); | ||
} else { | ||
@@ -240,3 +249,3 @@ return format(this._number, this.unit); | ||
get isZero() { | ||
return this.toNumber() === 0; | ||
return this._number.isZero(); | ||
} | ||
@@ -243,0 +252,0 @@ |
{ | ||
"name": "@exodus/currency", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Currency support.", | ||
@@ -12,4 +12,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"bignumber.js": "4.x" | ||
"big-rational": "^0.10.7" | ||
} | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
11739
9
303
0
1
+ Addedbig-rational@^0.10.7
+ Addedbig-integer@1.6.52(transitive)
+ Addedbig-rational@0.10.9(transitive)
- Removedbignumber.js@4.x
- Removedbignumber.js@4.1.0(transitive)