A proper and semantic typeof function that works with literal primitives, boxed objects and those from another execution context.
Kindof.js provides the
kindof function that does what you'd expect from
typeof — gives you the proper semantic type regardless if the variable was a primitive literal (
"Hello"), a boxed object (
new String("Hello")) or came from another execution context (e.g. an array from another
Kindof.js supports all ECMAScript built-in types and classes:
Function and plain old
Object. Others, e.g.
JSON, are considered just objects. In general, objects that behave like value objects (numbers, dates etc.) or proper arrays have a kind other than
Please see the table below for the full list of kinds.
Note: Kindof.js follows semantic versioning.
Take the index.js file, rename it how you'd like and source it at will.
npm install kindof.
And require with
var kindof = require("kindof").
Then continue as you would:
kindof"Hello" // => "string"kindof"Hello" // => "string"
The pattern is simple — all built-in objects that behave like value objects (numbers, strings, dates etc.) or are real arrays are said to be of a kind other than
arguments object, however, is not a proper array, so it therefore is an
Subclassed objects, such as subclassed arrays, are considered to be
object unless their internal
[[Class]] property remains
Array. For ways to subclass properly, please see further reading below.
typeofoperator in ECMAScript 5.1.
typeofoperator as implemented by Firefox.
Arrayby Juriy Zaytsev.
Kindof.js is released under a Lesser GNU Affero General Public License, which in summary means:
For more convoluted language, see the