mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Simplify _.parseInt.
This commit is contained in:
@@ -137,18 +137,6 @@
|
|||||||
return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
|
return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/** Used to detect and test for whitespace. */
|
|
||||||
var whitespace = (
|
|
||||||
// Basic whitespace characters.
|
|
||||||
' \t\x0b\f\xa0\ufeff' +
|
|
||||||
|
|
||||||
// Line terminators.
|
|
||||||
'\n\r\u2028\u2029' +
|
|
||||||
|
|
||||||
// Unicode category "Zs" space separators.
|
|
||||||
'\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
|
|
||||||
);
|
|
||||||
|
|
||||||
/** Used to assign default `context` object properties. */
|
/** Used to assign default `context` object properties. */
|
||||||
var contextProps = [
|
var contextProps = [
|
||||||
'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
|
'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
|
||||||
@@ -10517,25 +10505,16 @@
|
|||||||
* // => [6, 8, 10]
|
* // => [6, 8, 10]
|
||||||
*/
|
*/
|
||||||
function parseInt(string, radix, guard) {
|
function parseInt(string, radix, guard) {
|
||||||
if (guard && isIterateeCall(string, radix, guard)) {
|
// Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
|
||||||
|
// Chrome fails to trim leading <BOM> whitespace characters.
|
||||||
|
// See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
|
||||||
|
if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
|
||||||
radix = 0;
|
radix = 0;
|
||||||
|
} else if (radix) {
|
||||||
|
radix = +radix;
|
||||||
}
|
}
|
||||||
return nativeParseInt(string, radix);
|
string = trim(string);
|
||||||
}
|
return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
|
||||||
// Fallback for environments with pre-ES5 implementations.
|
|
||||||
if (nativeParseInt(whitespace + '08') != 8) {
|
|
||||||
parseInt = function(string, radix, guard) {
|
|
||||||
// Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
|
|
||||||
// Chrome fails to trim leading <BOM> whitespace characters.
|
|
||||||
// See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
|
|
||||||
if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
|
|
||||||
radix = 0;
|
|
||||||
} else if (radix) {
|
|
||||||
radix = +radix;
|
|
||||||
}
|
|
||||||
string = trim(string);
|
|
||||||
return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user