41 lines
1.2 KiB
Markdown
41 lines
1.2 KiB
Markdown
|
|
|
|
# Functions
|
|
|
|
<a id="hexfixlength"></a>
|
|
|
|
## hexFixLength
|
|
|
|
▸ **hexFixLength**(value: *`string`*, bitLength?: *`number`*, withPadding?: *`boolean`*): `string`
|
|
|
|
*Defined in [hex/fixLength.ts:24](https://github.com/polkadot-js/common/blob/49b0c84/packages/util/src/hex/fixLength.ts#L24)*
|
|
|
|
*__name__*: hexFixLength
|
|
|
|
*__summary__*: Shifts a hex string to a specific bitLength
|
|
|
|
*__description__*: 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). Values with more bits are trimmed to the specified length. Input values with less bits are returned as-is by default. When `withPadding` is set, shorter values are padded with `0`.
|
|
|
|
*__example__*:
|
|
|
|
```javascript
|
|
import { hexFixLength } from '@polkadot/util';
|
|
|
|
console.log('fixed', hexFixLength('0x12', 16)); // => 0x12
|
|
console.log('fixed', hexFixLength('0x12', 16, true)); // => 0x0012
|
|
console.log('fixed', hexFixLength('0x0012', 8)); // => 0x12
|
|
```
|
|
|
|
**Parameters:**
|
|
|
|
| Name | Type | Default value |
|
|
| ------ | ------ | ------ |
|
|
| value | `string` | - |
|
|
| `Default value` bitLength | `number` | -1 |
|
|
| `Default value` withPadding | `boolean` | false |
|
|
|
|
**Returns:** `string`
|
|
|
|
___
|
|
|