forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.ts
More file actions
74 lines (62 loc) · 1.69 KB
/
Utils.ts
File metadata and controls
74 lines (62 loc) · 1.69 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
74
import { JSFuck } from '../enums/JSFuck';
export class Utils {
/**
* @type {string}
*/
public static readonly hexadecimalPrefix: string = '0x';
/**
* @param {number} dec
* @returns {string}
*/
public static decToHex (dec: number): string {
const radix: number = 16;
return dec.toString(radix);
}
/**
* @param {string} url
* @returns {string}
*/
public static extractDomainFromUrl (url: string): string {
let domain: string;
if (url.indexOf('://') > -1 || url.indexOf('//') === 0) {
domain = url.split('/')[2];
} else {
domain = url.split('/')[0];
}
domain = domain.split(':')[0];
return domain;
}
/**
* @param {number} number
* @returns {boolean}
*/
public static isCeilNumber (number: number): boolean {
return number % 1 === 0;
}
/**
* @param {string} string
* @param {number} times
* @returns {string}
*/
public static stringRotate (string: string, times: number): string {
if (!string) {
throw new ReferenceError(`Cannot rotate empty string.`);
}
for (let i: number = 0; i < times; i++) {
string = string[string.length - 1] + string.substring(0, string.length - 1);
}
return string;
}
/**
* @param {string} string
* @returns {string}
*/
public static stringToJSFuck (string: string): string {
return Array
.from(string)
.map((character: string): string => {
return JSFuck[<any>character] || character;
})
.join(' + ');
}
}