Add hexFixLength documentation (#44)
This commit is contained in:
+19
@@ -3,6 +3,7 @@
|
||||
Internal utilities to create and test for hex values
|
||||
|
||||
- [hexAddPrefix](#hexaddprefix) Adds the `0x` prefix to string values.
|
||||
- [hexFixLength](#hexfixlength) Pads or shifts a hex string to a specific bitLength
|
||||
- [hexFromBn](#hexfrombn) Creates a hex value from a BN.js bignumber object.
|
||||
- [hexFromBn](#hexfrombn) Creates a hex value from a Buffer object.
|
||||
- [hexFromNumber](#hexfromnumber) Creates a hex value from a number.
|
||||
@@ -29,6 +30,24 @@ import { hexAddPrefix } from '@polkadot/util';
|
||||
console.log('With prefix', hexAddPrefix('0a0b12')) // => 0x0a0b12
|
||||
```
|
||||
|
||||
## hexFixLength
|
||||
|
||||
Pads or shifts a hex string to a specific bitLength
|
||||
|
||||
```js
|
||||
hexFixLength (value: string, bitLength: number = -1): string
|
||||
```
|
||||
|
||||
|
||||
Returns a `0x` prefixed string with the specified number of bits contained in the return value. (If bitLength is -1, length checking is not done). Input values with less bits are zero-padded, values with more bits are trimmed to the specified length.
|
||||
|
||||
```js
|
||||
import { hexFixLength } from '@polkadot/util';
|
||||
|
||||
console.log('fixed', hexFixLength('0x12', 16)) // => 0x0012
|
||||
console.log('fixed', hexFixLength('0x0012', 8)) // => 0x12
|
||||
```
|
||||
|
||||
## hexFromBn
|
||||
|
||||
Creates a hex value from a BN.js bignumber object. [(alias of bnToHex)](bn.md#bntohex)
|
||||
|
||||
Reference in New Issue
Block a user