mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 12:05:41 +03:00
refactor(size): Use instanceof checks instead of calling Object#toString
This commit is contained in:
parent
f6be4d7ad6
commit
62abb65493
@ -41,9 +41,9 @@ export function size<T>(target: T[] | object | string | Map<unknown, T> | Set<T>
|
||||
return 0;
|
||||
}
|
||||
|
||||
const tag = Object.prototype.toString.call(target);
|
||||
if (tag === '[object Map]' || tag === '[object Set]') {
|
||||
return (target as Map<unknown, T> | Set<T>).size;
|
||||
if (target instanceof Map || target instanceof Set) {
|
||||
return target.size;
|
||||
}
|
||||
|
||||
return Object.keys(target).length;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user