Handle 0 on numberToU8a (#626)
* Handle 0 on numberToU8a * Remove old test (replaced) * base58 CHANGELOG
This commit is contained in:
@@ -5,12 +5,6 @@
|
||||
import { numberToU8a } from '.';
|
||||
|
||||
describe('numberToU8a', (): void => {
|
||||
it('converts 0 to empty', (): void => {
|
||||
expect(
|
||||
numberToU8a(0)
|
||||
).toEqual(new Uint8Array());
|
||||
});
|
||||
|
||||
it('converts undefined to empty', (): void => {
|
||||
expect(
|
||||
numberToU8a()
|
||||
@@ -29,6 +23,18 @@ describe('numberToU8a', (): void => {
|
||||
).toEqual(new Uint8Array());
|
||||
});
|
||||
|
||||
it('converts 0 to u8a', (): void => {
|
||||
expect(
|
||||
numberToU8a(0)
|
||||
).toEqual(new Uint8Array([0]));
|
||||
});
|
||||
|
||||
it('converts 0 to u8a (with length)', (): void => {
|
||||
expect(
|
||||
numberToU8a(0, 16)
|
||||
).toEqual(new Uint8Array([0, 0]));
|
||||
});
|
||||
|
||||
it('converts values to the u8a', (): void => {
|
||||
expect(
|
||||
numberToU8a(0x3456)
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import hexToU8a from '../hex/toU8a';
|
||||
import isNull from '../is/null';
|
||||
import isUndefined from '../is/undefined';
|
||||
import numberToHex from './toHex';
|
||||
|
||||
/**
|
||||
@@ -20,7 +22,7 @@ import numberToHex from './toHex';
|
||||
* ```
|
||||
*/
|
||||
export default function numberToU8a (value?: number | null, bitLength = -1): Uint8Array {
|
||||
if (!value || isNaN(value)) {
|
||||
if (isUndefined(value) || isNull(value) || isNaN(value)) {
|
||||
return new Uint8Array();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user