| 241 | } |
| 242 | |
| 243 | export function toNumber(value) { |
| 244 | const type = typeof value; |
| 245 | const NAN = 0 / 0; |
| 246 | if (type === 'number') { |
| 247 | return value; |
| 248 | } |
| 249 | if ( |
| 250 | type === 'symbol' || |
| 251 | (type === 'object' && getTag(value) === '[object Symbol]') |
| 252 | ) { |
| 253 | return NAN; |
| 254 | } |
| 255 | if (isObject(value)) { |
| 256 | const other = typeof value.valueOf === 'function' ? value.valueOf() : value; |
| 257 | value = isObject(other) ? `${other}` : other; |
| 258 | } |
| 259 | if (type !== 'string') { |
| 260 | return value === 0 ? value : +value; |
| 261 | } |
| 262 | value = value.replace(/^\s+|\s+$/g, ''); |
| 263 | const isBinary = /^0b[01]+$/i.test(value); |
| 264 | return isBinary || /^0o[0-7]+$/i.test(value) |
| 265 | ? parseInt(value.slice(2), isBinary ? 2 : 8) |
| 266 | : /^[-+]0x[0-9a-f]+$/i.test(value) |
| 267 | ? NAN |
| 268 | : +value; |
| 269 | } |
| 270 | |
| 271 | export function isFunction(value) { |
| 272 | if (!isObject(value)) { |