UNPKG

476 BJavaScriptView Raw
1import { hexToBn } from './toBn.js';
2/**
3 * @name hexToNumber
4 * @summary Creates a Number value from a Buffer object.
5 * @description
6 * `null` inputs returns an NaN result, `hex` values return the actual value as a `Number`.
7 * @example
8 * <BR>
9 *
10 * ```javascript
11 * import { hexToNumber } from '@polkadot/util';
12 *
13 * hexToNumber('0x1234'); // => 0x1234
14 * ```
15 */
16export function hexToNumber(value) {
17 return value
18 ? hexToBn(value).toNumber()
19 : NaN;
20}