(instance: any)
| 8 | import { AribtraryObject, Constructor } from './types'; |
| 9 | |
| 10 | export function typeOf(instance: any) { |
| 11 | const t = typeof instance; |
| 12 | const c = (classOf(instance) as any); |
| 13 | switch (t) { |
| 14 | case 'number': |
| 15 | return Number.isNaN(instance) ? 'NaN' : 'number'; |
| 16 | |
| 17 | case 'object': |
| 18 | if (instance === null) { |
| 19 | return 'null'; |
| 20 | } |
| 21 | if (is.promise(instance)) { |
| 22 | return c.class ? `Promise<${classOf(c.class)?.name || parentClassOf(classOf(c.class)!)?.name}>` : 'Promise'; |
| 23 | } |
| 24 | return classOf(instance)?.name || parentClassOf(classOf(instance)!)?.name || '<anonymous>'; |
| 25 | case 'function': |
| 26 | if (is.Constructor(instance)) { |
| 27 | return `class ${c?.name || parentClassOf(c!)?.name || '<anonymous>'}`; |
| 28 | } |
| 29 | return 'function'; |
| 30 | |
| 31 | } |
| 32 | return t; |
| 33 | } |
| 34 | |
| 35 | export function hierarchy(instance: AribtraryObject | Constructor): string[] { |
| 36 | const result = new Array<string>(); |
no test coverage detected