Handle u8a null inputs in formatters (#134)

This commit is contained in:
Jaco Greeff
2018-06-11 10:16:03 +02:00
committed by GitHub
parent f2fb9603cc
commit 9186a46bf9
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -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([]);
+1 -1
View File
@@ -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'
: '';
+1 -1
View File
@@ -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);