refactor(size): Use instanceof checks instead of calling Object#toString

This commit is contained in:
raon0211 2024-08-09 09:35:41 +09:00
parent f6be4d7ad6
commit 62abb65493

View File

@ -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;
}