1 var baseKeys = require('./_baseKeys'),
2 getTag = require('./_getTag'),
3 isArrayLike = require('./isArrayLike'),
4 isString = require('./isString'),
5 stringSize = require('./_stringSize');
7 /** `Object#toString` result references. */
8 var mapTag = '[object Map]',
9 setTag = '[object Set]';
12 * Gets the size of `collection` by returning its length for array-like
13 * values or the number of own enumerable string keyed properties for objects.
18 * @category Collection
19 * @param {Array|Object|string} collection The collection to inspect.
20 * @returns {number} Returns the collection size.
26 * _.size({ 'a': 1, 'b': 2 });
32 function size(collection) {
33 if (collection == null) {
36 if (isArrayLike(collection)) {
37 return isString(collection) ? stringSize(collection) : collection.length;
39 var tag = getTag(collection);
40 if (tag == mapTag || tag == setTag) {
41 return collection.size;
43 return baseKeys(collection).length;
46 module.exports = size;