UNPKG

bbo

Version:

bbo is a utility library of zero dependencies for javascript.

33 lines (26 loc) 811 B
import './get_tag.js'; import isArray from './is_array.js'; import isString from './is_string.js'; import isMap from './is_map.js'; import isSet from './is_set.js'; /** * Gets the size of `collection` by returning its length for array-like * values or the number of own enumerable string keyed properties for objects. * * @category Collection * @param {Array|Object|string} collection The collection to inspect. * @returns {number} Returns the collection size. */ function size(collection) { if (collection === null || collection === undefined) { return 0; } if (isArray(collection) || isString(collection)) { return collection.length; } if (isMap(collection) || isSet(collection)) { return collection.size; } return Object.keys(collection).length; } export default size;