UNPKG

3.3 kBTypeScriptView Raw
1declare module '@ember/utils/lib/type-of' {
2 export type TypeName =
3 | 'undefined'
4 | 'null'
5 | 'string'
6 | 'number'
7 | 'boolean'
8 | 'function'
9 | 'array'
10 | 'regexp'
11 | 'date'
12 | 'filelist'
13 | 'class'
14 | 'instance'
15 | 'error'
16 | 'object';
17 /**
18 @module @ember/utils
19 */
20 /**
21 Returns a consistent type for the passed object.
22
23 Use this instead of the built-in `typeof` to get the type of an item.
24 It will return the same result across all browsers and includes a bit
25 more detail. Here is what will be returned:
26
27 | Return Value | Meaning |
28 |---------------|------------------------------------------------------|
29 | 'string' | String primitive or String object. |
30 | 'number' | Number primitive or Number object. |
31 | 'boolean' | Boolean primitive or Boolean object. |
32 | 'null' | Null value |
33 | 'undefined' | Undefined value |
34 | 'function' | A function |
35 | 'array' | An instance of Array |
36 | 'regexp' | An instance of RegExp |
37 | 'date' | An instance of Date |
38 | 'filelist' | An instance of FileList |
39 | 'class' | An Ember class (created using EmberObject.extend()) |
40 | 'instance' | An Ember object instance |
41 | 'error' | An instance of the Error object |
42 | 'object' | A JavaScript object not inheriting from EmberObject |
43
44 Examples:
45
46 ```javascript
47 import { A } from '@ember/array';
48 import { typeOf } from '@ember/utils';
49 import EmberObject from '@ember/object';
50
51 typeOf(); // 'undefined'
52 typeOf(null); // 'null'
53 typeOf(undefined); // 'undefined'
54 typeOf('michael'); // 'string'
55 typeOf(new String('michael')); // 'string'
56 typeOf(101); // 'number'
57 typeOf(new Number(101)); // 'number'
58 typeOf(true); // 'boolean'
59 typeOf(new Boolean(true)); // 'boolean'
60 typeOf(A); // 'function'
61 typeOf(A()); // 'array'
62 typeOf([1, 2, 90]); // 'array'
63 typeOf(/abc/); // 'regexp'
64 typeOf(new Date()); // 'date'
65 typeOf(event.target.files); // 'filelist'
66 typeOf(EmberObject.extend()); // 'class'
67 typeOf(EmberObject.create()); // 'instance'
68 typeOf(new Error('teamocil')); // 'error'
69
70 // 'normal' JavaScript object
71 typeOf({ a: 'b' }); // 'object'
72 ```
73
74 @method typeOf
75 @for @ember/utils
76 @param item the item to check
77 @return {String} the type
78 @public
79 @static
80 */
81 export default function typeOf(item: unknown): TypeName;
82}