ee-types
Easy and reliable type detection with ES6+ support.
Supported by joinbox.com, your swiss node.js & javascript agency 🚀
Compatibility
For a version supporting older browsers and node version please use ee-types version < 3.0.0.
Compatible with node 10+ (--experimental-modules
flag) and browsers supporting es modules.
Importing
node
;
browser
from html
<script type="module" src="node_modules/ee-types/src/types.mjs"></script>
from within a module
;
API
Be aware that the different object types like Maps, Promises and so on are not
detected as objects but as their respective type. If you need to detect them as
objects please use the types.someObject()
method instead of the types.object()
method.
Explicitly test for a type.
types // true
Get the type of some variable
// regexp
Supported Types
- string
- number
- boolean
- array
- intArray
- floatArray
- object
- function
- symbol
- date
- regexp
- error
- undefined
- buffer
- null
- arrayBuffer
- map
- weakMap
- set
- weakSet
- dataView
- float32Array
- float64Array
- int8Array
- int16Array
- int32Array
- uInt8Array
- uInt16Array
- uInt32Array
- uInt8ClampedArray
- generator
- promise
- someObject
Object Types
Since many of the types defined by javascript are just special objects that also can be treated as normal objects ee-types has a bunch of methods that allow you to handle that correctly.
For example, Map
is an object, or a custom class where you
define a getter that returns a specific name for your object:
const X = class { return 'AQL query';; }; console;// prints: [object AQL Query]
Check for a classic object
typesobject{}; // truetypesobject; // false // be aware that if you are not explicitly testing// for an object any object will be treated as one // 'object' // 'object'
Check any type of object
types; // truetypes; // false // 'object'
Examples
var types = ; types; // truetypes; // true // number // array // array // int8Array types // true