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

web3-utils

Package Overview
Dependencies
Maintainers
4
Versions
494
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-utils - npm Package Compare versions

Comparing version 4.2.4-dev.dd172c7.0 to 4.2.4-dev.de3e8f8.0

18

lib/commonjs/converters.js

@@ -60,2 +60,3 @@ "use strict";

};
const PrecisionLossWarning = 'Warning: Using type `number` with values that are large or contain many decimals may cause loss of precision, it is recommended to use type `string` or `BigInt` when using conversion methods';
/**

@@ -373,2 +374,3 @@ * Convert a value from bytes to Uint8Array

if (value > 1e+20) {
console.warn(PrecisionLossWarning);
// JavaScript converts numbers >= 10^21 to scientific notation when coerced to strings,

@@ -496,5 +498,19 @@ // leading to potential parsing errors and incorrect representations.

}
let parsedNumber = number;
if (typeof parsedNumber === 'number') {
if (parsedNumber < 1e-15) {
console.warn(PrecisionLossWarning);
}
if (parsedNumber > 1e+20) {
console.warn(PrecisionLossWarning);
parsedNumber = BigInt(parsedNumber);
}
else {
// in case there is a decimal point, we need to convert it to string
parsedNumber = parsedNumber.toLocaleString('fullwide', { useGrouping: false, maximumFractionDigits: 20 });
}
}
// if value is decimal e.g. 24.56 extract `integer` and `fraction` part
// to avoid `fraction` to be null use `concat` with empty string
const [integer, fraction] = String(typeof number === 'string' && !(0, web3_validator_1.isHexStrict)(number) ? number : (0, exports.toNumber)(number))
const [integer, fraction] = String(typeof parsedNumber === 'string' && !(0, web3_validator_1.isHexStrict)(parsedNumber) ? parsedNumber : (0, exports.toNumber)(parsedNumber))
.split('.')

@@ -501,0 +517,0 @@ .concat('');

@@ -57,2 +57,3 @@ /*

};
const PrecisionLossWarning = 'Warning: Using type `number` with values that are large or contain many decimals may cause loss of precision, it is recommended to use type `string` or `BigInt` when using conversion methods';
/**

@@ -358,2 +359,3 @@ * Convert a value from bytes to Uint8Array

if (value > 1e+20) {
console.warn(PrecisionLossWarning);
// JavaScript converts numbers >= 10^21 to scientific notation when coerced to strings,

@@ -478,5 +480,19 @@ // leading to potential parsing errors and incorrect representations.

}
let parsedNumber = number;
if (typeof parsedNumber === 'number') {
if (parsedNumber < 1e-15) {
console.warn(PrecisionLossWarning);
}
if (parsedNumber > 1e+20) {
console.warn(PrecisionLossWarning);
parsedNumber = BigInt(parsedNumber);
}
else {
// in case there is a decimal point, we need to convert it to string
parsedNumber = parsedNumber.toLocaleString('fullwide', { useGrouping: false, maximumFractionDigits: 20 });
}
}
// if value is decimal e.g. 24.56 extract `integer` and `fraction` part
// to avoid `fraction` to be null use `concat` with empty string
const [integer, fraction] = String(typeof number === 'string' && !isHexStrict(number) ? number : toNumber(number))
const [integer, fraction] = String(typeof parsedNumber === 'string' && !isHexStrict(parsedNumber) ? parsedNumber : toNumber(parsedNumber))
.split('.')

@@ -483,0 +499,0 @@ .concat('');

10

package.json
{
"name": "web3-utils",
"sideEffects": false,
"version": "4.2.4-dev.dd172c7.0+dd172c7",
"version": "4.2.4-dev.de3e8f8.0+de3e8f8",
"description": "Collection of utility functions used in web3.js.",

@@ -68,7 +68,7 @@ "main": "./lib/commonjs/index.js",

"eventemitter3": "^5.0.1",
"web3-errors": "1.1.5-dev.dd172c7.0+dd172c7",
"web3-types": "1.6.1-dev.dd172c7.0+dd172c7",
"web3-validator": "2.0.6-dev.dd172c7.0+dd172c7"
"web3-errors": "1.1.5-dev.de3e8f8.0+de3e8f8",
"web3-types": "1.6.1-dev.de3e8f8.0+de3e8f8",
"web3-validator": "2.0.6-dev.de3e8f8.0+de3e8f8"
},
"gitHead": "dd172c78daa518778aa2ac07aa2cc2a8bf0aa9e2"
"gitHead": "de3e8f881cc12ca6bbeddaf992c18c6c4eb1ede0"
}

@@ -80,2 +80,4 @@ /*

const PrecisionLossWarning = 'Warning: Using type `number` with values that are large or contain many decimals may cause loss of precision, it is recommended to use type `string` or `BigInt` when using conversion methods';
export type EtherUnits = keyof typeof ethUnitMap;

@@ -419,3 +421,4 @@ /**

if (typeof value === 'number') {
if (value > 1e+20) {
if (value > 1e+20) {
console.warn(PrecisionLossWarning)
// JavaScript converts numbers >= 10^21 to scientific notation when coerced to strings,

@@ -560,7 +563,21 @@ // leading to potential parsing errors and incorrect representations.

}
let parsedNumber = number;
if (typeof parsedNumber === 'number'){
if (parsedNumber < 1e-15){
console.warn(PrecisionLossWarning)
}
if (parsedNumber > 1e+20) {
console.warn(PrecisionLossWarning)
parsedNumber = BigInt(parsedNumber);
} else {
// in case there is a decimal point, we need to convert it to string
parsedNumber = parsedNumber.toLocaleString('fullwide', {useGrouping: false, maximumFractionDigits: 20})
}
}
// if value is decimal e.g. 24.56 extract `integer` and `fraction` part
// to avoid `fraction` to be null use `concat` with empty string
const [integer, fraction] = String(
typeof number === 'string' && !isHexStrict(number) ? number : toNumber(number),
typeof parsedNumber === 'string' && !isHexStrict(parsedNumber) ? parsedNumber : toNumber(parsedNumber),
)

@@ -572,2 +589,3 @@ .split('.')

// 24.56 -> 2456
const value = BigInt(`${integer}${fraction}`);

@@ -574,0 +592,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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