UNPKG

558 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import { hexToBn } from "./toBn.js";
4/**
5 * @name hexToNumber
6 * @summary Creates a Number value from a Buffer object.
7 * @description
8 * `null` inputs returns an NaN result, `hex` values return the actual value as a `Number`.
9 * @example
10 * <BR>
11 *
12 * ```javascript
13 * import { hexToNumber } from '@polkadot/util';
14 *
15 * hexToNumber('0x1234'); // => 0x1234
16 * ```
17 */
18
19export function hexToNumber(value) {
20 return value ? hexToBn(value).toNumber() : NaN;
21}
\No newline at end of file