react-json-tree
Version:
React JSON Viewer Component, Extracted from redux-devtools
18 lines (15 loc) • 436 B
text/typescript
export default function objType(obj: any) {
const type = Object.prototype.toString.call(obj).slice(8, -1);
if (type === 'Object' && typeof obj[Symbol.iterator] === 'function') {
return 'Iterable';
}
if (
type === 'Custom' &&
obj.constructor !== Object &&
obj instanceof Object
) {
// For projects implementing objects overriding `.prototype[Symbol.toStringTag]`
return 'Object';
}
return type;
}