1 | var baseKeys = require('./_baseKeys'),
|
2 | getTag = require('./_getTag'),
|
3 | isArrayLike = require('./isArrayLike'),
|
4 | isString = require('./isString'),
|
5 | stringSize = require('./_stringSize');
|
6 |
|
7 |
|
8 | var mapTag = '[object Map]',
|
9 | setTag = '[object Set]';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function size(collection) {
|
33 | if (collection == null) {
|
34 | return 0;
|
35 | }
|
36 | if (isArrayLike(collection)) {
|
37 | return isString(collection) ? stringSize(collection) : collection.length;
|
38 | }
|
39 | var tag = getTag(collection);
|
40 | if (tag == mapTag || tag == setTag) {
|
41 | return collection.size;
|
42 | }
|
43 | return baseKeys(collection).length;
|
44 | }
|
45 |
|
46 | module.exports = size;
|