UNPKG

881 BTypeScriptView Raw
1import type { HexString } from '../types.js';
2/**
3 * @name hexFixLength
4 * @summary Shifts a hex string to a specific bitLength
5 * @description
6 * 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`.
7 * @example
8 * <BR>
9 *
10 * ```javascript
11 * import { hexFixLength } from '@polkadot/util';
12 *
13 * console.log('fixed', hexFixLength('0x12', 16)); // => 0x12
14 * console.log('fixed', hexFixLength('0x12', 16, true)); // => 0x0012
15 * console.log('fixed', hexFixLength('0x0012', 8)); // => 0x12
16 * ```
17 */
18export declare function hexFixLength(value: string, bitLength?: number, withPadding?: boolean): HexString;