chai
Version:
BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
21 lines (18 loc) • 384 B
JavaScript
/**
* @param {unknown} obj
* @returns {string}
*/
export function type(obj) {
if (typeof obj === 'undefined') {
return 'undefined';
}
if (obj === null) {
return 'null';
}
const stringTag = obj[Symbol.toStringTag];
if (typeof stringTag === 'string') {
return stringTag;
}
const type = Object.prototype.toString.call(obj).slice(8, -1);
return type;
}