UNPKG

bbo

Version:

bbo is a utility library of zero dependencies for javascript.

35 lines (27 loc) 850 B
'use strict'; require('./get_tag.js'); var is_array = require('./is_array.js'); var is_string = require('./is_string.js'); var is_map = require('./is_map.js'); var is_set = require('./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 (is_array(collection) || is_string(collection)) { return collection.length; } if (is_map(collection) || is_set(collection)) { return collection.size; } return Object.keys(collection).length; } module.exports = size;