Socket
Socket
Sign inDemoInstall

@arcblock/forge-util

Package Overview
Dependencies
Maintainers
2
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcblock/forge-util - npm Package Compare versions

Comparing version 0.37.0 to 0.38.0

2

lib/index.d.ts

@@ -92,4 +92,2 @@ // Generate by [js2dts@0.3.3](https://github.com/whxaxes/js2dts#readme)

hexToNumber: (value: any) => number;
hexToNumberString: (value: any) => string;
numberToBN: any;
isHex: (hex: string) => boolean;

@@ -96,0 +94,0 @@ isHexStrict: (hex: string) => boolean;

51

lib/index.js

@@ -114,2 +114,6 @@ /* eslint-disable no-bitwise */

try {
if (typeof number === 'number' && number > 0) {
const numStr = Number(number).toLocaleString('fullwide', { useGrouping: false });
return new BN(numStr, 10);
}
return numberToBN(number);

@@ -217,17 +221,2 @@ } catch (error) {

/**
* Converts value to it's decimal representation in string
*
* @public
* @static
* @method hexToNumberString
* @param {String|Number|BN} value
* @returns {String}
*/
const hexToNumberString = value => {
if (!value) return value;
return toBN(value).toString(10);
};
/**
* Converts value to it's hex representation

@@ -365,2 +354,6 @@ *

if (typeof arg === 'number') {
if (typeof number === 'number' && arg > 0) {
return Number(arg).toLocaleString('fullwide', { useGrouping: false });
}
return String(arg);

@@ -393,4 +386,4 @@ }

const fromUnitToToken = (input, decimal = 18, optionsInput) => {
let arc = numberToBN(input);
const negative = arc.lt(zero);
let unit = toBN(input);
const negative = unit.lt(zero);
const base = toBN(`1${'0'.repeat(decimal)}`, 10);

@@ -401,6 +394,6 @@ const baseLength = base.toString(10).length - 1 || 1;

if (negative) {
arc = arc.mul(negative1);
unit = unit.mul(negative1);
}
let fraction = arc.mod(base).toString(10);
let fraction = unit.mod(base).toString(10);
while (fraction.length < baseLength) {

@@ -415,3 +408,3 @@ fraction = `0${fraction}`;

let whole = arc.div(base).toString(10);
let whole = unit.div(base).toString(10);
if (options.commify) {

@@ -439,3 +432,3 @@ whole = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ',');

const fromTokenToUnit = (input, decimal = 18) => {
let ether = numberToString(input);
let token = numberToString(input);
const base = toBN(`1${'0'.repeat(decimal)}`, 10);

@@ -445,15 +438,15 @@ const baseLength = base.toString(10).length - 1 || 1;

// Is it negative?
const negative = ether.substring(0, 1) === '-';
const negative = token.substring(0, 1) === '-';
if (negative) {
ether = ether.substring(1);
token = token.substring(1);
}
if (ether === '.') {
throw new Error(`error converting number ${input} to arc, invalid value`);
if (token === '.') {
throw new Error(`error converting token ${input} to unit, invalid value`);
}
// Split it into a whole and fractional part
const comps = ether.split('.');
const comps = token.split('.');
if (comps.length > 2) {
throw new Error(`error converting number ${input} to arc, too many decimal points`);
throw new Error(`error converting token ${input} to unit, too many decimal points`);
}

@@ -471,3 +464,3 @@

if (fraction.length > baseLength) {
throw new Error(`error converting number ${input} to arc, too many decimal places`);
throw new Error(`error converting token ${input} to unit, too many decimal places`);
}

@@ -643,4 +636,2 @@

hexToNumber,
hexToNumberString,
numberToBN,
isHex,

@@ -647,0 +638,0 @@ isHexStrict,

{
"name": "@arcblock/forge-util",
"version": "0.37.0",
"version": "0.38.0",
"description": "utils shared across mutlipe forge js libs, works in both node.js and browser",

@@ -56,3 +56,3 @@ "keywords": [

},
"gitHead": "d13d76de774d7e6a94fba6187f272ceaddc61e30"
"gitHead": "95052cc8a2af7e06daaebd8a57dfca3e282f8f7c"
}
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