mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Remove toLength.
This commit is contained in:
38
lodash.js
38
lodash.js
@@ -616,7 +616,11 @@
|
|||||||
/** Used to restore the original `_` reference in `noConflict` */
|
/** Used to restore the original `_` reference in `noConflict` */
|
||||||
var oldDash = context._;
|
var oldDash = context._;
|
||||||
|
|
||||||
/** Used as the maximum value returned by `toLength` */
|
/**
|
||||||
|
* Used as the maximum length an array-like object.
|
||||||
|
* See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength)
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
var maxSafeInteger = Math.pow(2, 53) - 1;
|
var maxSafeInteger = Math.pow(2, 53) - 1;
|
||||||
|
|
||||||
/** Used to resolve the internal [[Class]] of values */
|
/** Used to resolve the internal [[Class]] of values */
|
||||||
@@ -1343,8 +1347,7 @@
|
|||||||
iterable = collection,
|
iterable = collection,
|
||||||
length = collection ? collection.length : 0;
|
length = collection ? collection.length : 0;
|
||||||
|
|
||||||
if (typeof length == 'number') {
|
if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) {
|
||||||
length = toLength(length);
|
|
||||||
if (support.unindexedChars && isString(iterable)) {
|
if (support.unindexedChars && isString(iterable)) {
|
||||||
iterable = iterable.split('');
|
iterable = iterable.split('');
|
||||||
}
|
}
|
||||||
@@ -1372,8 +1375,7 @@
|
|||||||
var iterable = collection,
|
var iterable = collection,
|
||||||
length = collection ? collection.length : 0;
|
length = collection ? collection.length : 0;
|
||||||
|
|
||||||
if (typeof length == 'number') {
|
if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) {
|
||||||
length = toLength(length);
|
|
||||||
if (support.unindexedChars && isString(iterable)) {
|
if (support.unindexedChars && isString(iterable)) {
|
||||||
iterable = iterable.split('');
|
iterable = iterable.split('');
|
||||||
}
|
}
|
||||||
@@ -2205,20 +2207,6 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts `value` to an integer suitable for use as the length of an array-like
|
|
||||||
* object. See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength)
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {*} value The value to convert.
|
|
||||||
* @returns {number} Returns the converted integer.
|
|
||||||
*/
|
|
||||||
function toLength(value) {
|
|
||||||
var result = +value || 0;
|
|
||||||
return result < 0 ? 0 : (result < maxSafeInteger ? result : maxSafeInteger);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3573,10 +3561,10 @@
|
|||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
function contains(collection, target, fromIndex) {
|
function contains(collection, target, fromIndex) {
|
||||||
var length = toLength(collection && collection.length);
|
var length = collection ? collection.length : 0;
|
||||||
fromIndex = (typeof fromIndex == 'number' && +fromIndex) || 0;
|
fromIndex = (typeof fromIndex == 'number' && +fromIndex) || 0;
|
||||||
|
|
||||||
if (length) {
|
if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) {
|
||||||
if (typeof collection == 'string' || !isArray(collection) && isString(collection)) {
|
if (typeof collection == 'string' || !isArray(collection) && isString(collection)) {
|
||||||
if (fromIndex >= length) {
|
if (fromIndex >= length) {
|
||||||
return false;
|
return false;
|
||||||
@@ -4470,7 +4458,7 @@
|
|||||||
collection = collection.split('');
|
collection = collection.split('');
|
||||||
}
|
}
|
||||||
if (n == null || guard) {
|
if (n == null || guard) {
|
||||||
var length = toLength(collection && collection.length);
|
var length = collection ? collection.length : 0;
|
||||||
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
|
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
|
||||||
}
|
}
|
||||||
var result = shuffle(collection);
|
var result = shuffle(collection);
|
||||||
@@ -4529,7 +4517,9 @@
|
|||||||
*/
|
*/
|
||||||
function size(collection) {
|
function size(collection) {
|
||||||
var length = collection ? collection.length : 0;
|
var length = collection ? collection.length : 0;
|
||||||
return typeof length == 'number' && length > -1 ? length : keys(collection).length;
|
return (typeof length == 'number' && length > -1 && length <= maxSafeInteger)
|
||||||
|
? length
|
||||||
|
: keys(collection).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -4690,7 +4680,7 @@
|
|||||||
*/
|
*/
|
||||||
function toArray(collection) {
|
function toArray(collection) {
|
||||||
var length = collection && collection.length;
|
var length = collection && collection.length;
|
||||||
if (typeof length == 'number' && length > -1) {
|
if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) {
|
||||||
return (support.unindexedChars && isString(collection))
|
return (support.unindexedChars && isString(collection))
|
||||||
? collection.split('')
|
? collection.split('')
|
||||||
: slice(collection);
|
: slice(collection);
|
||||||
|
|||||||
Reference in New Issue
Block a user