Function
typeOf (item) String public
Module: | @ember/utils |
---|
Defined in packages/@ember/-internals/runtime/lib/type-of.js:24
import { typeOf } from '@ember/utils';
- item
- Object
- the item to check
- returns
- String
- the type
Returns a consistent type for the passed object.
Use this instead of the built-in typeof
to get the type of an item. It will return the same result across all browsers and includes a bit more detail. Here is what will be returned:
| Return Value | Meaning | |---------------|------------------------------------------------------| | 'string' | String primitive or String object. | | 'number' | Number primitive or Number object. | | 'boolean' | Boolean primitive or Boolean object. | | 'null' | Null value | | 'undefined' | Undefined value | | 'function' | A function | | 'array' | An instance of Array | | 'regexp' | An instance of RegExp | | 'date' | An instance of Date | | 'filelist' | An instance of FileList | | 'class' | An Ember class (created using EmberObject.extend()) | | 'instance' | An Ember object instance | | 'error' | An instance of the Error object | | 'object' | A JavaScript object not inheriting from EmberObject |
Examples:
import { A } from '@ember/array'; import { typeOf } from '@ember/utils'; import EmberObject from '@ember/object'; typeOf(); // 'undefined' typeOf(null); // 'null' typeOf(undefined); // 'undefined' typeOf('michael'); // 'string' typeOf(new String('michael')); // 'string' typeOf(101); // 'number' typeOf(new Number(101)); // 'number' typeOf(true); // 'boolean' typeOf(new Boolean(true)); // 'boolean' typeOf(A); // 'function' typeOf(A()); // 'array' typeOf([1, 2, 90]); // 'array' typeOf(/abc/); // 'regexp' typeOf(new Date()); // 'date' typeOf(event.target.files); // 'filelist' typeOf(EmberObject.extend()); // 'class' typeOf(EmberObject.create()); // 'instance' typeOf(new Error('teamocil')); // 'error' // 'normal' JavaScript object typeOf({ a: 'b' }); // 'object'
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Futils/typeOf