UNPKG

613 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3
4/**
5 * @name u8aToBuffer
6 * @summary Creates a Buffer object from a hex string.
7 * @description
8 * `null` inputs returns an empty `Buffer` result. `UInt8Array` input values return the actual bytes value converted to a `Buffer`. Anything that is not a `UInt8Array` throws an error.
9 * @example
10 * <BR>
11 *
12 * ```javascript
13 * import { u8aToBuffer } from '@polkadot/util';
14 *
15 * console.log('Buffer', u8aToBuffer('0x123480001f'));
16 * ```
17 */
18export function u8aToBuffer(value) {
19 return Buffer.from(value || []);
20}
\No newline at end of file