COLLECTED BY
Organization:
Internet Archive
Focused crawls are collections of frequently-updated webcrawl data from narrow (as opposed to broad or wide) web crawls, often focused on a single domain or subdomain.
The Wayback Machine - https://web.archive.org/web/20201220222254/https://github.com/lodash/lodash/blob/master/size.js
Permalink
Cannot retrieve contributors at this time
43 lines (40 sloc)
1.05 KB
import getTag from './.internal/getTag.js'
import isArrayLike from './isArrayLike.js'
import isString from './isString.js'
import stringSize from './.internal/stringSize.js'
/** `Object#toString` result references. */
const mapTag = '[object Map]'
const setTag = '[object Set]'
/**
* Gets the size of `collection` by returning its length for array-like
* values or the number of own enumerable string keyed properties for objects.
*
* @since 0.1.0
* @category Collection
* @param {Array|Object|string } 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 ) ) {
return isString ( collection ) ? stringSize ( collection ) : collection . length
}
const tag = getTag ( collection )
if ( tag == mapTag || tag == setTag ) {
return collection . size
}
return Object . keys ( collection ) . length
}
export default size
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.