@polkadot/util
Advanced tools
Comparing version 10.1.9 to 10.1.10
@@ -5,5 +5,2 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
import { nToU8a } from "./toU8a.js"; | ||
/** @internal */ | ||
const ZERO_STR = '0x00'; | ||
/** | ||
@@ -19,3 +16,3 @@ * @name nToHex | ||
} = {}) { | ||
return !value ? ZERO_STR : u8aToHex(nToU8a(value, { | ||
return u8aToHex(nToU8a(value || 0, { | ||
bitLength, | ||
@@ -22,0 +19,0 @@ isLe, |
@@ -45,3 +45,3 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
if (valueBi === _0n) { | ||
return bitLength === -1 ? new Uint8Array() : new Uint8Array(Math.ceil((bitLength || 0) / 8)); | ||
return bitLength === -1 ? new Uint8Array(1) : new Uint8Array(Math.ceil((bitLength || 0) / 8)); | ||
} | ||
@@ -48,0 +48,0 @@ |
@@ -5,3 +5,2 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
import { bnToU8a } from "./toU8a.js"; | ||
const ZERO_STR = '0x00'; | ||
/** | ||
@@ -28,3 +27,3 @@ * @name bnToHex | ||
} = {}) { | ||
return !value ? ZERO_STR : u8aToHex(bnToU8a(value, { | ||
return u8aToHex(bnToU8a(value, { | ||
bitLength, | ||
@@ -31,0 +30,0 @@ isLe, |
@@ -33,3 +33,3 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
if (!value) { | ||
return bitLength === -1 ? new Uint8Array() : new Uint8Array(byteLength); | ||
return bitLength === -1 ? new Uint8Array(1) : new Uint8Array(byteLength); | ||
} | ||
@@ -36,0 +36,0 @@ |
@@ -15,4 +15,2 @@ "use strict"; | ||
/** @internal */ | ||
const ZERO_STR = '0x00'; | ||
/** | ||
@@ -22,3 +20,2 @@ * @name nToHex | ||
*/ | ||
function nToHex(value) { | ||
@@ -30,3 +27,3 @@ let { | ||
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return !value ? ZERO_STR : (0, _u8a.u8aToHex)((0, _toU8a.nToU8a)(value, { | ||
return (0, _u8a.u8aToHex)((0, _toU8a.nToU8a)(value || 0, { | ||
bitLength, | ||
@@ -33,0 +30,0 @@ isLe, |
@@ -56,3 +56,3 @@ "use strict"; | ||
if (valueBi === _consts._0n) { | ||
return bitLength === -1 ? new Uint8Array() : new Uint8Array(Math.ceil((bitLength || 0) / 8)); | ||
return bitLength === -1 ? new Uint8Array(1) : new Uint8Array(Math.ceil((bitLength || 0) / 8)); | ||
} | ||
@@ -59,0 +59,0 @@ |
@@ -14,3 +14,3 @@ "use strict"; | ||
// SPDX-License-Identifier: Apache-2.0 | ||
const ZERO_STR = '0x00'; | ||
/** | ||
@@ -31,3 +31,2 @@ * @name bnToHex | ||
*/ | ||
function bnToHex(value) { | ||
@@ -39,3 +38,3 @@ let { | ||
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return !value ? ZERO_STR : (0, _u8a.u8aToHex)((0, _toU8a.bnToU8a)(value, { | ||
return (0, _u8a.u8aToHex)((0, _toU8a.bnToU8a)(value, { | ||
bitLength, | ||
@@ -42,0 +41,0 @@ isLe, |
@@ -42,3 +42,3 @@ "use strict"; | ||
if (!value) { | ||
return bitLength === -1 ? new Uint8Array() : new Uint8Array(byteLength); | ||
return bitLength === -1 ? new Uint8Array(1) : new Uint8Array(byteLength); | ||
} | ||
@@ -45,0 +45,0 @@ |
@@ -30,9 +30,4 @@ "use strict"; | ||
let bitLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; | ||
if (value === undefined || value === null || isNaN(value)) { | ||
return '0x'; | ||
} | ||
const hex = value.toString(16); | ||
const hex = (!value || Number.isNaN(value) ? 0 : value).toString(16); | ||
return (0, _fixLength.hexFixLength)(hex.length % 2 ? `0${hex}` : hex, bitLength, true); | ||
} |
@@ -31,3 +31,3 @@ "use strict"; | ||
let bitLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; | ||
return value === undefined || value === null || isNaN(value) ? new Uint8Array() : (0, _toU8a.hexToU8a)((0, _toHex.numberToHex)(value, bitLength)); | ||
return (0, _toU8a.hexToU8a)((0, _toHex.numberToHex)(value, bitLength)); | ||
} |
@@ -14,4 +14,4 @@ "use strict"; | ||
type: 'cjs', | ||
version: '10.1.9' | ||
version: '10.1.10' | ||
}; | ||
exports.packageInfo = packageInfo; |
@@ -21,8 +21,4 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
export function numberToHex(value, bitLength = -1) { | ||
if (value === undefined || value === null || isNaN(value)) { | ||
return '0x'; | ||
} | ||
const hex = value.toString(16); | ||
const hex = (!value || Number.isNaN(value) ? 0 : value).toString(16); | ||
return hexFixLength(hex.length % 2 ? `0${hex}` : hex, bitLength, true); | ||
} |
@@ -21,3 +21,3 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
export function numberToU8a(value, bitLength = -1) { | ||
return value === undefined || value === null || isNaN(value) ? new Uint8Array() : hexToU8a(numberToHex(value, bitLength)); | ||
return hexToU8a(numberToHex(value, bitLength)); | ||
} |
@@ -23,3 +23,3 @@ { | ||
"type": "module", | ||
"version": "10.1.9", | ||
"version": "10.1.10", | ||
"main": "./cjs/index.js", | ||
@@ -723,6 +723,6 @@ "module": "./index.js", | ||
"@babel/runtime": "^7.19.0", | ||
"@polkadot/x-bigint": "10.1.9", | ||
"@polkadot/x-global": "10.1.9", | ||
"@polkadot/x-textdecoder": "10.1.9", | ||
"@polkadot/x-textencoder": "10.1.9", | ||
"@polkadot/x-bigint": "10.1.10", | ||
"@polkadot/x-global": "10.1.10", | ||
"@polkadot/x-textdecoder": "10.1.10", | ||
"@polkadot/x-textencoder": "10.1.10", | ||
"@types/bn.js": "^5.1.1", | ||
@@ -729,0 +729,0 @@ "bn.js": "^5.2.1" |
@@ -8,3 +8,3 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
type: 'esm', | ||
version: '10.1.9' | ||
version: '10.1.10' | ||
}; |
Sorry, the diff of this file is too big to display
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
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
148916
530940
15257
2
3
0
7
+ Added@polkadot/x-bigint@10.1.10(transitive)
+ Added@polkadot/x-global@10.1.10(transitive)
+ Added@polkadot/x-textdecoder@10.1.10(transitive)
+ Added@polkadot/x-textencoder@10.1.10(transitive)
- Removed@polkadot/x-bigint@10.1.9(transitive)
- Removed@polkadot/x-global@10.1.9(transitive)
- Removed@polkadot/x-textdecoder@10.1.9(transitive)
- Removed@polkadot/x-textencoder@10.1.9(transitive)
Updated@polkadot/x-bigint@10.1.10
Updated@polkadot/x-global@10.1.10