UNPKG

lodash-es

Version:

The modern build of lodash exported as ES modules.

31 lines (28 loc) 750 B
import getLength from '../internal/getLength'; import isLength from '../internal/isLength'; import keys from '../object/keys'; /** * Gets the size of `collection` by returning its length for array-like * values or the number of own enumerable properties for objects. * * @static * @memberOf _ * @category Collection * @param {Array|Object|string} collection The collection to inspect. * @returns {number} Returns the size of `collection`. * @example * * _.size([1, 2, 3]); * // => 3 * * _.size({ 'a': 1, 'b': 2 }); * // => 2 * * _.size('pebbles'); * // => 7 */ function size(collection) { var length = collection ? getLength(collection) : 0; return isLength(length) ? length : keys(collection).length; } export default size;