typeof2
Version:
Very small and fast Javascript type acquisition method.
11 lines (10 loc) • 413 B
JavaScript
;
/**
* Get type
* @param {any} arg Need to get the type of data
* @returns {object}
*/
let t,
type = arg => (t = typeof arg) === "object" ? {}.toString.call(arg).slice(8,-1).toLowerCase() : t,
name = arg => (t = type(arg)) === "function" ? arg.name : t === "undefined" ? undefined : t === "null" ? null : arg?.constructor?.name;
module.exports = arg => ({type:type(arg),name:name(arg)});