@makerdao/currency
Advanced tools
Comparing version 0.9.9 to 0.9.10
@@ -47,2 +47,3 @@ 'use strict'; | ||
function amountToBigNumber(amount) { | ||
if (amount._isBigNumber && amount._hex) amount = amount._hex; | ||
if (amount instanceof Currency || typeof amount.toBigNumber === 'function') return amount.toBigNumber(); | ||
@@ -76,4 +77,5 @@ | ||
var decimals = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2; | ||
var symbol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
return this._amount.toFixed(decimals) + ' ' + this.symbol; | ||
return symbol ? this._amount.toFixed(decimals) + ' ' + this.symbol : this._amount.toFixed(decimals); | ||
} | ||
@@ -80,0 +82,0 @@ }, { |
{ | ||
"name": "@makerdao/currency", | ||
"description": "Utilities for working with currency amounts", | ||
"version": "0.9.9", | ||
"version": "0.9.10", | ||
"license": "MIT", | ||
@@ -20,2 +20,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@ethersproject/bignumber": "^5.5.0", | ||
"babel-cli": "^6.26.0", | ||
@@ -22,0 +23,0 @@ "babel-jest": "^22.4.3", |
import BigNumber from 'bignumber.js'; | ||
function amountToBigNumber(amount) { | ||
if (amount._isBigNumber && amount._hex) amount = amount._hex; | ||
if (amount instanceof Currency || typeof amount.toBigNumber === 'function') | ||
@@ -27,4 +28,6 @@ return amount.toBigNumber(); | ||
toString(decimals = 2) { | ||
return `${this._amount.toFixed(decimals)} ${this.symbol}`; | ||
toString(decimals = 2, symbol = true) { | ||
return symbol | ||
? `${this._amount.toFixed(decimals)} ${this.symbol}` | ||
: this._amount.toFixed(decimals); | ||
} | ||
@@ -31,0 +34,0 @@ |
import { Currency, createCurrency, createCurrencyRatio } from '../src'; | ||
import BigNumber from 'bignumber.js'; | ||
import { BigNumber as EthersBN } from '@ethersproject/bignumber'; | ||
@@ -44,2 +45,7 @@ const DAI = createCurrency('DAI'); | ||
test('toString accepts a boolean to not print symbol', () => { | ||
const n = MKR('1000.5447123'); | ||
expect(n.toString(3, false)).toBe('1000.545'); | ||
}); | ||
test('basic math', () => { | ||
@@ -154,2 +160,8 @@ const a = MKR('1.2'); | ||
expect(val.eq(5)).toBeTruthy(); | ||
}); | ||
}); | ||
test('can safely handle ethers bignumber (BN.js)', () => { | ||
const ethersBN = EthersBN.from(555); | ||
const val = ETH(ethersBN); | ||
expect(val.eq(555)).toBeTruthy(); | ||
}); |
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
29855
727
7
1