mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Bump to v4.7.0.
This commit is contained in:
11
toNumber.js
11
toNumber.js
@@ -1,4 +1,4 @@
|
||||
define(['./isFunction', './isObject'], function(isFunction, isObject) {
|
||||
define(['./isFunction', './isObject', './isSymbol'], function(isFunction, isObject, isSymbol) {
|
||||
|
||||
/** Used as references for various `Number` constants. */
|
||||
var NAN = 0 / 0;
|
||||
@@ -23,6 +23,7 @@ define(['./isFunction', './isObject'], function(isFunction, isObject) {
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.0.0
|
||||
* @category Lang
|
||||
* @param {*} value The value to process.
|
||||
* @returns {number} Returns the number.
|
||||
@@ -41,12 +42,18 @@ define(['./isFunction', './isObject'], function(isFunction, isObject) {
|
||||
* // => 3
|
||||
*/
|
||||
function toNumber(value) {
|
||||
if (typeof value == 'number') {
|
||||
return value;
|
||||
}
|
||||
if (isSymbol(value)) {
|
||||
return NAN;
|
||||
}
|
||||
if (isObject(value)) {
|
||||
var other = isFunction(value.valueOf) ? value.valueOf() : value;
|
||||
value = isObject(other) ? (other + '') : other;
|
||||
}
|
||||
if (typeof value != 'string') {
|
||||
return value === 0 ? value : +value;
|
||||
return value === 0 ? value : +value;
|
||||
}
|
||||
value = value.replace(reTrim, '');
|
||||
var isBinary = reIsBinary.test(value);
|
||||
|
||||
Reference in New Issue
Block a user