1 var isObject = require(
'./isObject'),
2 isSymbol = require(
'./isSymbol');
8 var reTrim = /^\s+|\s+$/g;
11 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
14 var reIsBinary = /^0b[01]+$/i;
17 var reIsOctal = /^0o[0-7]+$/i;
20 var freeParseInt = parseInt;
45 function toNumber(value) {
46 if (typeof value ==
'number') {
49 if (isSymbol(value)) {
52 if (isObject(value)) {
53 var other = typeof value.valueOf ==
'function' ? value.valueOf() : value;
54 value = isObject(other) ? (other +
'') : other;
56 if (typeof value !=
'string') {
57 return value === 0 ? value : +value;
59 value = value.replace(reTrim,
'');
60 var isBinary = reIsBinary.test(value);
61 return (isBinary || reIsOctal.test(value))
62 ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
63 : (reIsBadHex.test(value) ? NAN : +value);
66 module.exports = toNumber;