mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
"use strict";
|
|
class Utils {
|
|
static arrayRotate(array, times, reverse = false) {
|
|
if (times < 0) {
|
|
return;
|
|
}
|
|
let newArray = array, temp;
|
|
while (times--) {
|
|
if (!reverse) {
|
|
temp = newArray.pop();
|
|
newArray.unshift(temp);
|
|
}
|
|
else {
|
|
temp = newArray.shift();
|
|
newArray.push(temp);
|
|
}
|
|
}
|
|
return newArray;
|
|
}
|
|
static decToHex(dec) {
|
|
return (dec + Math.pow(16, 6)).toString(16).substr(-6);
|
|
}
|
|
static getRandomInteger(min, max) {
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
}
|
|
static getRandomVariableName(length = 6) {
|
|
const rangeMinInteger = 10000, rangeMaxInteger = 99999999, prefix = '_0x';
|
|
return `${prefix}${(Utils.decToHex(Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger))).substr(0, length)}`;
|
|
}
|
|
static stringToUnicode(string) {
|
|
return `'${string.replace(/[\s\S]/g, (escape) => {
|
|
return `\\u${('0000' + escape.charCodeAt(0).toString(16)).slice(-4)}`;
|
|
})}'`;
|
|
}
|
|
}
|
|
exports.Utils = Utils;
|