Remove {from,to}Buffer methods (#89)
* Remove all {from,to}Buffer utility methods
* Fix check & test
* Updsate docs
* Bump minor
This commit is contained in:
@@ -2,37 +2,9 @@
|
||||
|
||||
Utility methods to convert to and from `Buffer` objects
|
||||
|
||||
- [bufferFromHex](#bufferfromhex) Creates a Buffer object from a hex string.
|
||||
- [bufferFromNumber](#bufferfromnumber) Creates a Buffer object from a number.
|
||||
- [bufferFromU8a](#bufferfromu8a) Creates a Buffer object from a Uint8Array.
|
||||
- [bufferToHex](#buffertohex) Creates a hex value from a Buffer object.
|
||||
- [bufferToNumber](#buffertonumber) Creates a Number value from a Buffer object.
|
||||
- [bufferToU8a](#buffertou8a) Creates a Uint8Array value from a Buffer object.
|
||||
|
||||
## bufferFromHex
|
||||
|
||||
Creates a Buffer object from a hex string. [(alias of hexToBuffer)](hex.md#hextobuffer)
|
||||
|
||||
```js
|
||||
bufferFromHex (value?: string): Buffer
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## bufferFromNumber
|
||||
|
||||
Creates a Buffer object from a number. [(alias of numberToBuffer)](number.md#numbertobuffer)
|
||||
|
||||
```js
|
||||
bufferFromNumber (value?: number): Buffer
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## bufferFromU8a
|
||||
|
||||
Creates a Buffer object from a Uint8Array. [(alias of u8aToBuffer)](u8a.md#u8atobuffer)
|
||||
@@ -45,40 +17,6 @@ bufferFromU8a (value?: string): Buffer
|
||||
|
||||
|
||||
|
||||
## bufferToHex
|
||||
|
||||
Creates a hex value from a Buffer object.
|
||||
|
||||
```js
|
||||
bufferToHex (value?: Buffer): string
|
||||
```
|
||||
|
||||
|
||||
`null` inputs returns a `0x` result, `Buffer` values return the actual value as a `0x` prefixed hex value. Anything that is not a `Buffer` object throws an error.
|
||||
|
||||
```js
|
||||
import { bufferToHex } from '@polkadot/util';
|
||||
|
||||
bufferToHex(Buffer.from([1, 2, 3]); // => 0x010203
|
||||
```
|
||||
|
||||
## bufferToNumber
|
||||
|
||||
Creates a Number value from a Buffer object.
|
||||
|
||||
```js
|
||||
bufferToNumber (value?: Buffer): number
|
||||
```
|
||||
|
||||
|
||||
`null` inputs returns an NaN result, `Buffer` values return the actual value as a `Number`.
|
||||
|
||||
```js
|
||||
import { bufferToNumber } from '@polkadot/util';
|
||||
|
||||
bufferToNumber(Buffer.from([12, 34, 56])); // => 0x123456
|
||||
```
|
||||
|
||||
## bufferToU8a
|
||||
|
||||
Creates a Uint8Array value from a Buffer object.
|
||||
|
||||
@@ -5,12 +5,10 @@ Internal utilities to create and test for hex values
|
||||
- [hexAddPrefix](#hexaddprefix) Adds the `0x` prefix to string values.
|
||||
- [hexFixLength](#hexfixlength) Shifts a hex string to a specific bitLength
|
||||
- [hexFromBn](#hexfrombn) Creates a hex value from a BN.js bignumber object.
|
||||
- [hexFromBuffer](#hexfrombuffer) Creates a hex value from a Buffer object.
|
||||
- [hexFromNumber](#hexfromnumber) Creates a hex value from a number.
|
||||
- [hexHasPrefix](#hexhasprefix) Tests for the existence of a `0x` prefix.
|
||||
- [hexStripPrefix](#hexstripprefix) Strips any leading `0x` prefix.
|
||||
- [hexToBn](#hextobn) Creates a BN.js bignumber object from a hex string.
|
||||
- [hexToBuffer](#hextobuffer) Creates a Buffer object from a hex string.
|
||||
- [hexToNumber](#hextonumber) Creates a Number value from a Buffer object.
|
||||
- [hexToU8a](#hextou8a) Creates a Buffer object from a hex string.
|
||||
|
||||
@@ -62,18 +60,6 @@ hexFromBn (value?: BN): string
|
||||
|
||||
|
||||
|
||||
## hexFromBuffer
|
||||
|
||||
Creates a hex value from a Buffer object. [(alias of bufferToHex)](buffer.md#buffertohex)
|
||||
|
||||
```js
|
||||
hexFromBuffer (value?: Buffer): string
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## hexFromNumber
|
||||
|
||||
Creates a hex value from a number. [(alias of numberToHex)](number.md#numbertohex)
|
||||
@@ -137,23 +123,6 @@ import { hexToBn } from '@polkadot/util';
|
||||
hexToBn('0x123480001f'); // => BN(0x123480001f)
|
||||
```
|
||||
|
||||
## hexToBuffer
|
||||
|
||||
Creates a Buffer object from a hex string.
|
||||
|
||||
```js
|
||||
hexToBuffer (value?: string): Buffer
|
||||
```
|
||||
|
||||
|
||||
`null` inputs returns an empty `Buffer` result. Hex input values return the actual bytes value converted to a Buffer. Anything that is not a hex string (including the `0x` prefix) throws an error.
|
||||
|
||||
```js
|
||||
import { hexToBuffer } from '@polkadot/util';
|
||||
|
||||
hexToBuffer('0x123480001f'); // Buffer([0x12, 0x34, 0x80, 0x00, 0x1f])
|
||||
```
|
||||
|
||||
## hexToNumber
|
||||
|
||||
Creates a Number value from a Buffer object.
|
||||
|
||||
@@ -14,7 +14,7 @@ Type checking utilities
|
||||
- [isNumber](#isnumber) Tests for a JavaScript number.
|
||||
- [isObject](#isobject) Tests for an `object`.
|
||||
- [isString](#isstring) Tests for a string.
|
||||
- [isUint8Array](#isuint8array) Tests for a `Uint8Array` object instance.
|
||||
- [isU8a](#isu8a) Tests for a `Uint8Array` object instance.
|
||||
- [isUndefined](#isundefined) Tests for a `undefined` values.
|
||||
|
||||
## isBN
|
||||
@@ -227,12 +227,12 @@ import { isString } from '@polkadot/util';
|
||||
console.log('isString', isString('test')); // => true
|
||||
```
|
||||
|
||||
## isUint8Array
|
||||
## isU8a
|
||||
|
||||
Tests for a `Uint8Array` object instance.
|
||||
|
||||
```js
|
||||
isUint8Array (value: mixed): boolean
|
||||
isU8a (value: mixed): boolean
|
||||
```
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@ Checks to see if the input object is an instance of `Uint8Array`.
|
||||
```js
|
||||
import { isUint8Array } from '@polkadot/util';
|
||||
|
||||
console.log('isUint8Array', isUint8Array([])); // => false
|
||||
console.log('isU8a', isU8a([])); // => false
|
||||
```
|
||||
|
||||
## isUndefined
|
||||
|
||||
@@ -2,24 +2,10 @@
|
||||
|
||||
Utility methods to convert to and from `number` values
|
||||
|
||||
- [numberFromBuffer](#numberfrombuffer) Creates a Number value from a Buffer object.
|
||||
- [numberFromHex](#numberfromhex) Creates a Number value from a Buffer object.
|
||||
- [numberToBuffer](#numbertobuffer) Creates a Buffer object from a number.
|
||||
- [numberToHex](#numbertohex) Creates a hex value from a number.
|
||||
- [numberToU8a](#numbertou8a) Creates a Uint8Array object from a number.
|
||||
|
||||
## numberFromBuffer
|
||||
|
||||
Creates a Number value from a Buffer object. [(alias of bufferToNumber)](buffer.md#buffertonumber)
|
||||
|
||||
```js
|
||||
numberFromBuffer (value?: Buffer): number
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## numberFromHex
|
||||
|
||||
Creates a Number value from a Buffer object. [(alias of hexToNumber)](hex.md#hextonumber)
|
||||
@@ -32,23 +18,6 @@ numberFromHex (value?: Hex): number
|
||||
|
||||
|
||||
|
||||
## numberToBuffer
|
||||
|
||||
Creates a Buffer object from a number.
|
||||
|
||||
```js
|
||||
numberToBuffer (value?: number): Buffer
|
||||
```
|
||||
|
||||
|
||||
`null`/`undefined`/`NaN` inputs returns an empty `Buffer` result. `number` input values return the actual bytes value converted to a `Buffer`.
|
||||
|
||||
```js
|
||||
import { numberToBuffer } from '@polkadot/util';
|
||||
|
||||
const buffer = numberToBuffer(0x1234); // => Buffer.from([0x12, 0x34])
|
||||
```
|
||||
|
||||
## numberToHex
|
||||
|
||||
Creates a hex value from a number.
|
||||
@@ -72,7 +41,7 @@ numberToHex(0x1234, 32) // => 0x00001234
|
||||
Creates a Uint8Array object from a number.
|
||||
|
||||
```js
|
||||
numberToBuffer (value?: number, bitLenght: number = -1): Uint8Array
|
||||
numberToU8a (value?: number, bitLenght: number = -1): Uint8Array
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user