UNPKG

598 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3
4/**
5 * @name u8aEmpty
6 * @summary Tests for a `Uint8Array` for emptyness
7 * @description
8 * Checks to see if the input `Uint8Array` has zero length or contains all 0 values.
9 */
10export function u8aEmpty(value) {
11 // on smaller values < 64 bytes, the byte-by-byte compare is faster than
12 // allocating yet another object for DataView (on large buffers the DataView
13 // is much faster)
14 for (let i = 0; i < value.length; i++) {
15 if (value[i]) {
16 return false;
17 }
18 }
19
20 return true;
21}
\No newline at end of file