Returns the type name of the value passed, similar to the flawed typeof, but in a much richer, fine-grained & non-Bad Parts manner, recognising & many more distinct "real" types.
For example 'realObject' is considered only and for all real {} objects, in all object forms (i.e plain {} object, instance etc.) but does NOT include Arrays, Functions, Maps, Sets etc etc unlike typeof (and isObject for that matter).
Nestedly null's type is well... 'null' and not 'object', unlike JS's dummy typeof.
Also, functions are recognised as 'function' but ES6 Classes as 'class'.
And NaNs as just a 'NaN', not a number as the name stipulates!
Finally, it recognises many other built-in types, like Set, Map, Iterator, Generator, TypedArray, Promise and others.
Naming Conventions
The type name is returned as a string, where possible types names are among TypeNames.
We keep same names as [typeof](etc. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) when these type co-exist in typeof & z.type(). But we also add many more types, not needing adhere to the ill-formed legacy of typeof formatting and rules. So we have types like 'class', 'Generator', 'Iterator', 'Generator', 'Promise' etc. There's a distinction between primitives & boxed primitives, so we also have 'Number', 'String', 'Boolean' etc.
The convention is to use either:
the typeof name, for example string or number or function, if those co-exist (and make sense).
Otherwise, we use:
the TypeScript/ES6 built-in type name or construct (preferred, if it exists). For example, we choose "class" instead of "Class"
OR
the same name as the constructor function used to create the value, for example WeakSet *
Boxed values (of primitives) always get their type in capitalized form, i.e 'Number', 'String' or 'Boolean'.
Returns the type name of the value passed, similar to the flawed
typeof
, but in a much richer, fine-grained & non-Bad Parts manner, recognising & many more distinct "real" types.For example
'realObject'
is considered only and for all real{}
objects, in all object forms (i.e plain {} object, instance etc.) but does NOT include Arrays, Functions, Maps, Sets etc etc unliketypeof
(andisObject
for that matter).Nestedly
null
's type is well...'null'
and not'object'
, unlike JS's dummytypeof
.Also, functions are recognised as
'function'
but ES6 Classes as'class'
.And NaNs as just a
'NaN'
, not anumber
as the name stipulates!Finally, it recognises many other built-in types, like Set, Map, Iterator, Generator, TypedArray, Promise and others.
Naming Conventions
The type name is returned as a string, where possible types names are among TypeNames.
We keep same names as [typeof](etc. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) when these type co-exist in
typeof
&z.type()
. But we also add many more types, not needing adhere to the ill-formed legacy oftypeof
formatting and rules. So we have types like 'class', 'Generator', 'Iterator', 'Generator', 'Promise' etc. There's a distinction between primitives & boxed primitives, so we also have 'Number', 'String', 'Boolean' etc.The convention is to use either:
typeof
name, for examplestring
ornumber
orfunction
, if those co-exist (and make sense).Otherwise, we use:
WeakSet
*'Number'
,'String'
or'Boolean'
.