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 1.1.2 to 1.1.3

5

CHANGELOG.md

@@ -0,1 +1,6 @@

## 1.1.3 / 2021-09-28
- `toString`, `toNumberString`, and `toNumber` now accept an optional unit argument (unitInstance for toString, unit was already taken)
- deprecate direct `toNumberString` usage
## 1.1.2 / 2021-06-28

@@ -2,0 +7,0 @@

69

lib/number-unit.js

@@ -22,6 +22,6 @@ "use strict";

const reportDifferentTypesDeprecated = (num, otherNum) => {
const deprecationWarning = message => {
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(message);
console.warn('***************************************************************');

@@ -32,2 +32,6 @@ console.trace();

const reportDifferentTypesDeprecated = (num, otherNum) => {
deprecationWarning(`DEPRECATION WARNING: number-unit.add/sub on different NumberUnit types (${num}, ${otherNum}) is not correct and will be removed soon`);
};
class NumberUnit {

@@ -57,5 +61,5 @@ static create(num, unit) {

this._number = this._createNumber(num);
Object.defineProperty(this, '_numberString', {
Object.defineProperty(this, '_numberStringMap', {
enumerable: false,
value: null,
value: new Map(),
writable: true

@@ -260,3 +264,4 @@ });

} else {
const num = this.toNumberString();
const num = this._toNumberString();
const [whole] = num.split('.');

@@ -271,3 +276,4 @@ return new NumberUnit(whole, this.unit);

} else {
const num = this.toNumberString();
const num = this._toNumberString();
const [whole, fraction] = num.split('.');

@@ -288,3 +294,4 @@ let newNumber = new NumberUnit(whole, this.unit);

} else {
const num = this.toNumberString();
const num = this._toNumberString();
const [whole, fraction] = num.split('.');

@@ -374,3 +381,3 @@ let newNumber = new NumberUnit(whole, this.unit);

return {
value: this.toNumberString(),
value: this._toNumberString(),
unit: this.unitName,

@@ -382,4 +389,4 @@ unitType: this.unitType.toString(),

toNumber() {
return parseFloat(this.toNumberString());
toNumber(unit) {
return parseFloat(this._toNumberString(unit));
}

@@ -395,8 +402,18 @@

toNumberString() {
if (this._numberString) return this._numberString;
toNumberString(unit) {
deprecationWarning('DEPRECATION WARNING: number-unit.toNumberString usage will be removed soon. Use number-unit.toString({unit: false}) instead');
return this._toNumberString(unit);
}
let number = this._number.toString(10);
_toNumberString(unit = this.unit) {
const unitString = unit.toString();
if (this._numberStringMap.get(unitString)) return this._numberStringMap.get(unitString);
let numberUnit;
if (unit === this.unit) numberUnit = this;else numberUnit = this.to(unit);
if (this.unit.power === 0) {
let number = numberUnit._number.toString(10);
if (numberUnit.unit.power === 0) {
this._numberStringMap.set(unitString, number);
return number;

@@ -411,7 +428,7 @@ }

if (number.length < this.unit.power + 1) {
number = number.padStart(this.unit.power + 1, '0');
if (number.length < numberUnit.unit.power + 1) {
number = number.padStart(numberUnit.unit.power + 1, '0');
}
number = number.slice(0, -this.unit.power) + '.' + number.slice(-this.unit.power);
number = number.slice(0, -numberUnit.unit.power) + '.' + number.slice(-numberUnit.unit.power);
const pp = number.indexOf('.');

@@ -434,3 +451,4 @@

this._numberString = number;
this._numberStringMap.set(unitString, number);
return number;

@@ -441,8 +459,9 @@ }

unit = true,
format
format,
unitInstance = this.unit
} = {}) {
if (!format) {
return this.toNumberString() + (unit ? ' ' + this.unitName : '');
return this._toNumberString(unitInstance) + (unit ? ' ' + unitInstance.unitName : '');
} else {
return format(this.toNumberString(), this.unit);
return format(this._toNumberString(unitInstance), unitInstance);
}

@@ -473,9 +492,3 @@ }

if (NumberUnit.isNumberUnit(number)) return number;else {
try {
console.warn('***************************************************************');
console.warn('DEPRECATION WARNING: number-unit.add/sub usage with int or string param will be removed soon');
console.warn('***************************************************************');
console.trace();
} catch (err) {}
deprecationWarning('DEPRECATION WARNING: number-unit.add/sub usage with int or string param will be removed soon');
return new NumberUnit(number, this.unit);

@@ -482,0 +495,0 @@ }

{
"name": "@exodus/currency",
"version": "1.1.2",
"version": "1.1.3",
"description": "Currency support.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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