mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Bump to v4.7.0.
This commit is contained in:
15
size.js
15
size.js
@@ -1,14 +1,21 @@
|
||||
import getTag from './_getTag';
|
||||
import isArrayLike from './isArrayLike';
|
||||
import isObjectLike from './isObjectLike';
|
||||
import isString from './isString';
|
||||
import keys from './keys';
|
||||
import stringSize from './_stringSize';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var mapTag = '[object Map]',
|
||||
setTag = '[object Set]';
|
||||
|
||||
/**
|
||||
* Gets the size of `collection` by returning its length for array-like
|
||||
* values or the number of own enumerable properties for objects.
|
||||
* values or the number of own enumerable string keyed properties for objects.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 0.1.0
|
||||
* @category Collection
|
||||
* @param {Array|Object} collection The collection to inspect.
|
||||
* @returns {number} Returns the collection size.
|
||||
@@ -31,6 +38,12 @@ function size(collection) {
|
||||
var result = collection.length;
|
||||
return (result && isString(collection)) ? stringSize(collection) : result;
|
||||
}
|
||||
if (isObjectLike(collection)) {
|
||||
var tag = getTag(collection);
|
||||
if (tag == mapTag || tag == setTag) {
|
||||
return collection.size;
|
||||
}
|
||||
}
|
||||
return keys(collection).length;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user