better-type-of
A better typeof
install
npm install better-type-of
usage
; === 'null'; === 'reg exp'; === 'promise'; === 'generator function'; === 'html document';
why
Lots of libraries out there will check the type of a value and you can always call Object.prototype.toString yourself. This is different in that it's a simple function that returns more or less what you'd expect from typeof. Compare
ObjectprototypetoString === '[object HTMLDocument]'; === 'html document';
see also
- Fixing the JavaScript typeof operator
- Understanding JavaScript types and reliable type checking
- Why use toString() to typecheck args that you can check with typeof?
license
MIT