Handle u8a null inputs in formatters (#134)
This commit is contained in:
@@ -19,7 +19,7 @@ const hexStripPrefix = require('./stripPrefix');
|
||||
hexToU8a('0x80001f'); // Uint8Array([0x80, 0x00, 0x1f])
|
||||
hexToU8a('0x80001f', 32); // Uint8Array([0x00, 0x80, 0x00, 0x1f])
|
||||
*/
|
||||
module.exports = function hexToU8a (_value?: string, bitLength: number = -1): Uint8Array {
|
||||
module.exports = function hexToU8a (_value?: string | null, bitLength: number = -1): Uint8Array {
|
||||
// flowlint-next-line sketchy-null-string:off
|
||||
if (!_value) {
|
||||
return new Uint8Array([]);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
u8aToHex(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0xf])); // 0x68656c0f
|
||||
*/
|
||||
module.exports = function u8aToHex (value?: Uint8Array, bitLength: number = -1, isPrefixed: boolean = true): string {
|
||||
module.exports = function u8aToHex (value?: Uint8Array | null, bitLength: number = -1, isPrefixed: boolean = true): string {
|
||||
const prefix = isPrefixed
|
||||
? '0x'
|
||||
: '';
|
||||
|
||||
@@ -18,7 +18,7 @@ const hexToU8a = require('../hex/toU8a');
|
||||
u8aToU8a(new Uint8Array([0x12, 0x34]); // => Uint8Array([0x12, 0x34])
|
||||
u8aToU8a(0x1234); // => Uint8Array([0x12, 0x34])
|
||||
*/
|
||||
module.exports = function u8aToU8a (value?: Uint8Array | string): Uint8Array {
|
||||
module.exports = function u8aToU8a (value?: Uint8Array | string | null): Uint8Array {
|
||||
// flowlint-next-line sketchy-null-string:off
|
||||
if (!value) {
|
||||
return new Uint8Array(0);
|
||||
|
||||
Reference in New Issue
Block a user