@exodus/currency
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -22,2 +22,11 @@ "use strict"; | ||
const reportDifferentTypesDeprecated = (num, otherNum) => { | ||
try { | ||
console.warn('***************************************************************'); | ||
console.warn(`DEPRECATION WARNING: number-unit.add/sub on different NumberUnit types (${num}, ${otherNum}) is not correct and will be removed soon`); | ||
console.warn('***************************************************************'); | ||
console.trace(); | ||
} catch (err) {} | ||
}; | ||
class NumberUnit { | ||
@@ -161,2 +170,4 @@ static create(num, unit) { | ||
num = this._coerceToNumberUnit(num); | ||
if (num.unitType !== this.unitType) reportDifferentTypesDeprecated(this, num); | ||
if (num.isZero) return this;else if (this.isZero) return new NumberUnit(num._number, this.unit); | ||
return new NumberUnit(this._number.add(num._number), this.unit); | ||
@@ -308,2 +319,4 @@ } | ||
num = this._coerceToNumberUnit(num); | ||
if (num.unitType !== this.unitType) reportDifferentTypesDeprecated(this, num); | ||
if (num.isZero) return this;else if (this.isZero) return new NumberUnit(num._number.neg(), this.unit); | ||
return new NumberUnit(this._number.sub(num._number), this.unit); | ||
@@ -425,2 +438,6 @@ } | ||
get isPositive() { | ||
return this._number.gt(new _bn.default(0)); | ||
} | ||
get isZero() { | ||
@@ -427,0 +444,0 @@ return this._number.isZero(); |
{ | ||
"name": "@exodus/currency", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Currency support.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -10,3 +10,3 @@ Exodus Currency | ||
**It's currently only used in the mobile project.** It will be backported to Exotrack and Exodus Desktop. | ||
**It's currently used in desktop and mobile.** | ||
@@ -23,2 +23,19 @@ Install | ||
```js | ||
import assets from '@exodus/assets-base' | ||
import { UnitType } from '@exodus/currency' | ||
const ether = UnitType.create(assets.ethereum.units) | ||
const e1 = ether.ETH(2) | ||
const e2 = ether.parse('2 ETH') | ||
const e3 = e2.to('wei') | ||
const e4 = e3.add(ether.ETH(3)) | ||
const e5 = e4.toDefault() | ||
const e6 = e5.toBase() | ||
console.log(e1.equals(e2)) | ||
console.log(e2.equals(e3)) | ||
console.log(e4.toString()) | ||
console.log(e5.toString()) | ||
console.log(e6.toString()) | ||
``` |
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
21125
519
40
1