UNPKG

836 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.u8aToBuffer = void 0;
4const x_global_1 = require("@polkadot/x-global");
5const has_js_1 = require("../has.js");
6/**
7 * @name u8aToBuffer
8 * @summary Creates a Buffer object from a hex string.
9 * @description
10 * `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.
11 * @example
12 * <BR>
13 *
14 * ```javascript
15 * import { u8aToBuffer } from '@polkadot/util';
16 *
17 * console.log('Buffer', u8aToBuffer(new Uint8Array([1, 2, 3])));
18 * ```
19 */
20function u8aToBuffer(value) {
21 return has_js_1.hasBuffer
22 ? x_global_1.xglobal.Buffer.from(value || [])
23 : new Uint8Array(value || []);
24}
25exports.u8aToBuffer = u8aToBuffer;