Permalink
Cannot retrieve contributors at this time
46 lines (43 sloc)
1.11 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/lodash/size.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var baseKeys = require('./_baseKeys'), | |
getTag = require('./_getTag'), | |
isArrayLike = require('./isArrayLike'), | |
isString = require('./isString'), | |
stringSize = require('./_stringSize'); | |
/** `Object#toString` result references. */ | |
var mapTag = '[object Map]', | |
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. | |
* | |
* @static | |
* @memberOf _ | |
* @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; | |
} | |
var tag = getTag(collection); | |
if (tag == mapTag || tag == setTag) { | |
return collection.size; | |
} | |
return baseKeys(collection).length; | |
} | |
module.exports = size; |