Files
common/packages/util/src/u8a/toBuffer.ts
T
Jaco 3a98323e8b Minor readability improvements (#952)
* Minor readability improvements

* trigger

* Additional

* Additional
2021-04-21 10:31:28 +02:00

21 lines
643 B
TypeScript

// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
/**
* @name u8aToBuffer
* @summary Creates a Buffer object from a hex string.
* @description
* `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.
* @example
* <BR>
*
* ```javascript
* import { u8aToBuffer } from '@polkadot/util';
*
* console.log('Buffer', u8aToBuffer('0x123480001f'));
* ```
*/
export function u8aToBuffer (value?: Uint8Array | null): Buffer {
return Buffer.from(value || []);
}