1 | enum BasicTypes {
|
2 | number,
|
3 | boolean,
|
4 | string,
|
5 | object,
|
6 | date,
|
7 | function
|
8 | }
|
9 |
|
10 | enum BasicTypeScriptTypes {
|
11 | any,
|
12 | void
|
13 | }
|
14 |
|
15 | export class BasicTypeUtil {
|
16 | private static instance: BasicTypeUtil;
|
17 | private constructor() {}
|
18 | public static getInstance() {
|
19 | if (!BasicTypeUtil.instance) {
|
20 | BasicTypeUtil.instance = new BasicTypeUtil();
|
21 | }
|
22 | return BasicTypeUtil.instance;
|
23 | }
|
24 |
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 | public isJavascriptType(type: string): boolean {
|
31 | if (typeof type !== 'undefined' && type.toLowerCase) {
|
32 | return type.toLowerCase() in BasicTypes;
|
33 | } else {
|
34 | return false;
|
35 | }
|
36 | }
|
37 |
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 | public isTypeScriptType(type: string): boolean {
|
44 | if (typeof type !== 'undefined' && type.toLowerCase) {
|
45 | return type.toLowerCase() in BasicTypeScriptTypes;
|
46 | } else {
|
47 | return false;
|
48 | }
|
49 | }
|
50 |
|
51 | |
52 |
|
53 |
|
54 |
|
55 | public isKnownType(type: string): boolean {
|
56 | return this.isJavascriptType(type) || this.isTypeScriptType(type);
|
57 | }
|
58 |
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 | public getTypeUrl(type: string): string | undefined {
|
65 | if (this.isJavascriptType(type)) {
|
66 | return `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/${type}`;
|
67 | }
|
68 |
|
69 | if (this.isTypeScriptType(type)) {
|
70 | return `https://www.typescriptlang.org/docs/handbook/basic-types.html`;
|
71 | }
|
72 |
|
73 | return undefined;
|
74 | }
|
75 | }
|
76 |
|
77 | export default BasicTypeUtil.getInstance();
|