Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@exodus/currency

Package Overview
Dependencies
Maintainers
0
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@exodus/currency - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

CHANGELOG.md

57

lib/number-unit.js

@@ -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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc