mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
Bump to v4.7.0.
This commit is contained in:
15
size.js
15
size.js
@@ -1,11 +1,16 @@
|
||||
define(['./isArrayLike', './isString', './keys', './_stringSize'], function(isArrayLike, isString, keys, stringSize) {
|
||||
define(['./_getTag', './isArrayLike', './isObjectLike', './isString', './keys', './_stringSize'], function(getTag, isArrayLike, isObjectLike, isString, keys, 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.
|
||||
@@ -28,6 +33,12 @@ define(['./isArrayLike', './isString', './keys', './_stringSize'], function(isAr
|
||||
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