Files
common/packages/util/src/u8a/toBuffer.js
T
Jaco Greeff b5c5734c7c Add Blake2s & XXHash utility functions (#66)
* Initial split of util & util-crypto

* Add initial XXHash version

* Blake2s wit tests & documentation

* Add sha512 (from NaCl)

* Add randomBytes (from NaCl)

* Flow fixes

* Update documentation

* Update latest @polkadot/dev
2018-01-25 14:13:43 +01:00

24 lines
771 B
JavaScript

// Copyright 2017-2018 Jaco Greeff
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow
/**
@name u8aToBuffer
@signature u8aToBuffer (value?: UInt8Array): Buffer
@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
import { u8aToBuffer } from '@polkadot/util';
console.log('Buffer', u8aToBuffer('0x123480001f'));
*/
module.exports = function u8aToBuffer (value?: Uint8Array): Buffer {
if (!value) {
return Buffer.from([]);
}
return Buffer.from(value);
};