on master help sign in
bridge/src/lib/convertToInt.js
17 lines 363 B history raw
1import { isNaN } from 'lodash';
3/**
4 * a version of parseInt that throws for NaN
5 * fun fact, parseInt also handles 0x-prefixed hex strings, assuming the radix
6 * to be 16
7 *
8 * @throws
9 * @returns {number}
10 */
11export const convertToInt = (num, radix) => {
12 const res = parseInt(num, radix);
13 if (isNaN(res)) {
14 throw new Error('NaN');
15 }
16 return res;
17};