UNPKG

716 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import { u8aToU8a } from "./toU8a.js";
4/**
5 * @name u8aConcat
6 * @summary Creates a concatenated Uint8Array from the inputs.
7 * @description
8 * Concatenates the input arrays into a single `UInt8Array`.
9 * @example
10 * <BR>
11 *
12 * ```javascript
13 * import { { u8aConcat } from '@polkadot/util';
14 *
15 * u8aConcat(
16 * new Uint8Array([1, 2, 3]),
17 * new Uint8Array([4, 5, 6])
18 * ); // [1, 2, 3, 4, 5, 6]
19 * ```
20 */
21
22export function u8aConcat(...list) {
23 const u8as = new Array(list.length);
24
25 for (let i = 0; i < list.length; i++) {
26 u8as[i] = u8aToU8a(list[i]);
27 }
28
29 return Uint8Array.from(Buffer.concat(u8as));
30}
\No newline at end of file