safer type checking for iterable structures

This commit is contained in:
FredyC 2015-08-22 06:09:42 +02:00
parent 56de89c440
commit c76f755863

View File

@ -1,7 +1,6 @@
export default function(obj) {
const type = Object.prototype.toString.call(obj).slice(8, -1);
if (type === 'Object' && typeof obj[Symbol.iterator] === 'function') {
if (obj !== null && typeof obj === 'object' && typeof obj[Symbol.iterator] === 'function') {
return 'Iterable';
}
return type;
return Object.prototype.toString.call(obj).slice(8, -1);
}