mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
Bump to v4.0.0.
This commit is contained in:
37
size.js
Normal file
37
size.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import isArrayLike from './isArrayLike';
|
||||
import isString from './isString';
|
||||
import keys from './keys';
|
||||
import stringSize from './internal/stringSize';
|
||||
|
||||
/**
|
||||
* 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} collection The collection to inspect.
|
||||
* @returns {number} Returns the collection size.
|
||||
* @example
|
||||
*
|
||||
* _.size([1, 2, 3]);
|
||||
* // => 3
|
||||
*
|
||||
* _.size({ 'a': 1, 'b': 2 });
|
||||
* // => 2
|
||||
*
|
||||
* _.size('pebbles');
|
||||
* // => 7
|
||||
*/
|
||||
function size(collection) {
|
||||
if (collection == null) {
|
||||
return 0;
|
||||
}
|
||||
if (isArrayLike(collection)) {
|
||||
var result = collection.length;
|
||||
return (result && isString(collection)) ? stringSize(collection) : result;
|
||||
}
|
||||
return keys(collection).length;
|
||||
}
|
||||
|
||||
export default size;
|
||||
Reference in New Issue
Block a user