-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathUtils.ts
More file actions
73 lines (61 loc) · 1.89 KB
/
Utils.ts
File metadata and controls
73 lines (61 loc) · 1.89 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
export class Utils {
/**
* @type {string}
*/
public static readonly baseMultipleSourcesIdentifiersPrefix: string = 'a';
/**
* @type {string}
*/
public static readonly hexadecimalPrefix: string = '0x';
/**
* @param {string} version
* @param {string} buildTimestamp
* @returns {string}
*/
public static buildVersionMessage (version?: string, buildTimestamp?: string): string {
const isUnknownVersion = !version || !buildTimestamp;
if (isUnknownVersion) {
return 'unknown';
}
const buildDate: string = new Date(parseInt(buildTimestamp, 10)).toISOString();
return `${version}_${buildDate}`;
}
/**
* @param {string} url
* @returns {string}
*/
public static extractDomainFrom (url: string): string {
let domain: string;
if (url.includes('://') || url.indexOf('//') === 0) {
domain = url.split('/')[2];
} else {
domain = url.split('/')[0];
}
domain = domain.split(':')[0];
return domain;
}
/**
* @param {string | undefined} identifiersPrefix
* @param {number} sourceCodeIndex
* @returns {string}
*/
public static getIdentifiersPrefixForMultipleSources (
identifiersPrefix: string | undefined,
sourceCodeIndex: number
): string {
const baseIdentifiersPrefix: string = !!identifiersPrefix
? identifiersPrefix
: Utils.baseMultipleSourcesIdentifiersPrefix;
return `${baseIdentifiersPrefix}${sourceCodeIndex}`;
}
/**
* @param {TObject} enumLikeObject
* @returns {Readonly<TObject>}
*/
public static makeEnum<
TObject extends {[index: string]: TValue},
TValue extends string
> (enumLikeObject: TObject): Readonly<TObject> {
return Object.freeze({...enumLikeObject});
}
}