Function
typeOf (item) String public
Module:
@ember/utils
Defined in packages/@ember/utils/lib/type-of.ts:40
import { typeOf } from '@ember/utils'; |
- item
- 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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
| 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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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' |