better-type-of

A better type of

Usage no npm install needed!

<script type="module">
  import betterTypeOf from 'https://cdn.skypack.dev/better-type-of';
</script>

README

better-type-of

A better typeof

install

npm install better-type-of

usage

import typeOf from 'better-type-of';

typeOf(null) === 'null';
typeOf(/test/) === 'reg exp';
typeOf(Promise.resolve()) === 'promise';
typeOf(function *() {}) === 'generator function';
typeOf(document) === '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

Object.prototype.toString.call(document) === '[object HTMLDocument]';

typeOf(document) === 'html document';

see also

license

MIT