@@ -3,7 +3,7 @@
|
||||
|
||||
import { isU8a } from '.';
|
||||
|
||||
describe('isUint8Array', (): void => {
|
||||
describe('isU8a', (): void => {
|
||||
it('returns false on undefined values', (): void => {
|
||||
expect(
|
||||
isU8a()
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { u8aEmpty } from '.';
|
||||
|
||||
describe('u8aEmpty', (): void => {
|
||||
it('returns true on zero length', (): void => {
|
||||
expect(
|
||||
u8aEmpty(new Uint8Array())
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns true on all zero values', (): void => {
|
||||
expect(
|
||||
u8aEmpty(new Uint8Array([0, 0, 0, 0, 0, 0]))
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns false when value is found', (): void => {
|
||||
expect(
|
||||
u8aEmpty(new Uint8Array([0, 0, 0, 0, 0, 1]))
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* @name u8aEmpty
|
||||
* @summary Tests for a `Uint8Array` for emptyness
|
||||
* @description
|
||||
* Checks to see if the input `Uint8Array` has zero length or contains all 0 values.
|
||||
*/
|
||||
export function u8aEmpty (value: Uint8Array): boolean {
|
||||
return value.length === 0 || value.every((v) => !v);
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
export { u8aCmp } from './cmp';
|
||||
export { u8aConcat } from './concat';
|
||||
export { u8aEmpty } from './empty';
|
||||
export { u8aEq } from './eq';
|
||||
export { u8aFixLength } from './fixLength';
|
||||
export { u8aSorted } from './sorted';
|
||||
|
||||
Reference in New Issue
Block a user