mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Revert "perf(toNumber): use +value to convert binary/octal/hexadecimal string (#4230)"
This reverts commit 7084300d34.
This commit is contained in:
18
lodash.js
18
lodash.js
@@ -177,9 +177,18 @@
|
|||||||
/** Used to match `RegExp` flags from their coerced string values. */
|
/** Used to match `RegExp` flags from their coerced string values. */
|
||||||
var reFlags = /\w*$/;
|
var reFlags = /\w*$/;
|
||||||
|
|
||||||
|
/** Used to detect bad signed hexadecimal string values. */
|
||||||
|
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
||||||
|
|
||||||
|
/** Used to detect binary string values. */
|
||||||
|
var reIsBinary = /^0b[01]+$/i;
|
||||||
|
|
||||||
/** Used to detect host constructors (Safari). */
|
/** Used to detect host constructors (Safari). */
|
||||||
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
||||||
|
|
||||||
|
/** Used to detect octal string values. */
|
||||||
|
var reIsOctal = /^0o[0-7]+$/i;
|
||||||
|
|
||||||
/** Used to detect unsigned integer values. */
|
/** Used to detect unsigned integer values. */
|
||||||
var reIsUint = /^(?:0|[1-9]\d*)$/;
|
var reIsUint = /^(?:0|[1-9]\d*)$/;
|
||||||
|
|
||||||
@@ -400,7 +409,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** Built-in method references without a dependency on `root`. */
|
/** Built-in method references without a dependency on `root`. */
|
||||||
var freeParseFloat = parseFloat;
|
var freeParseFloat = parseFloat,
|
||||||
|
freeParseInt = parseInt;
|
||||||
|
|
||||||
/** Detect free variable `global` from Node.js. */
|
/** Detect free variable `global` from Node.js. */
|
||||||
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
||||||
@@ -12458,7 +12468,11 @@
|
|||||||
if (typeof value != 'string') {
|
if (typeof value != 'string') {
|
||||||
return value === 0 ? value : +value;
|
return value === 0 ? value : +value;
|
||||||
}
|
}
|
||||||
return +value;
|
value = value.replace(reTrim, '');
|
||||||
|
var isBinary = reIsBinary.test(value);
|
||||||
|
return (isBinary || reIsOctal.test(value))
|
||||||
|
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
||||||
|
: (reIsBadHex.test(value) ? NAN : +value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -23598,9 +23598,9 @@
|
|||||||
QUnit.test('`_.' + methodName + '` should convert binary/octal strings to numbers', function(assert) {
|
QUnit.test('`_.' + methodName + '` should convert binary/octal strings to numbers', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var numbers = [42, 5349, 1715004, 63, 42798, 27440068],
|
var numbers = [42, 5349, 1715004],
|
||||||
transforms = [identity, pad],
|
transforms = [identity, pad],
|
||||||
values = ['0b101010', '0o12345', '0x1a2b3c', ' 0b111111 ', ' 0o123456 ', ' 0x1a2b3c4 ' ];
|
values = ['0b101010', '0o12345', '0x1a2b3c'];
|
||||||
|
|
||||||
var expected = lodashStable.map(numbers, function(n) {
|
var expected = lodashStable.map(numbers, function(n) {
|
||||||
return lodashStable.times(8, lodashStable.constant(n));
|
return lodashStable.times(8, lodashStable.constant(n));
|
||||||
@@ -23620,7 +23620,7 @@
|
|||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var transforms = [identity, pad, positive, negative],
|
var transforms = [identity, pad, positive, negative],
|
||||||
values = ['0b', '0o', '0x', '0b1010102', '0o123458', '0x1a2b3x', '+0b101010', '+0o12345', '+0x1a2b3c'];
|
values = ['0b', '0o', '0x', '0b1010102', '0o123458', '0x1a2b3x'];
|
||||||
|
|
||||||
var expected = lodashStable.map(values, function(n) {
|
var expected = lodashStable.map(values, function(n) {
|
||||||
return lodashStable.times(8, lodashStable.constant(isToNumber ? NaN : 0));
|
return lodashStable.times(8, lodashStable.constant(isToNumber ? NaN : 0));
|
||||||
|
|||||||
Reference in New Issue
Block a user