# All files / src Utils.js

100% Statements 44/44
94.12% Branches 16/17
100% Functions 2/2
100% Lines 37/37

    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
    75
    76
    77
    78
    1x
    1x

    2065x

    8x
    8x
    4x

    4x
    4x
    895x
    893x
    893x

    2x
    2x

    4x

    1x

    214x
    214x

    80x

    78x
    78x
    78x

    136x

    1x

    7x

    36x

    156x
    156x
    156x
    964x
    953x
    953x

    11x
    11x

    964x

    1x
    1x
    1x
     "use strict";
    const chance_1 = require('chance');
    const JSFuck_1 = require('./enums/JSFuck');
    class Utils {
        static arrayContains(array, searchElement) {
            return array.indexOf(searchElement) >= 0;
        }
        static arrayRotate(array, times, reverse = false) {
            if (times <= 0) {
                return array;
            }
            let newArray = array, temp;
            while (times--) {
                if (!reverse) {
                    temp = newArray.pop();
                    newArray.unshift(temp);
                }
                else {
                    temp = newArray.shift();
                    newArray.push(temp);
                }
            }
            return newArray;
        }
        static btoa(string) {
            return new Buffer(encodeURI(string)).toString('base64');
        }
        static decToHex(dec) {
            const decToHexSliceValue = -6, exponent = 6, radix = 16;
            return (dec + Math.pow(radix, exponent))
                .toString(radix)
                .substr(decToHexSliceValue)
                .replace(Utils.hexRepetitiveZerosRegExp, '');
        }
        static getRandomGenerator() {
            return Utils.randomGenerator;
        }
        static getRandomVariableName(length = 6) {
            const rangeMinInteger = 10000, rangeMaxInteger = 99999999, prefix = '_0x';
            return `${prefix}${(Utils.decToHex(Utils.getRandomGenerator().integer({
                min: rangeMinInteger,
                max: rangeMaxInteger
            }))).substr(0, length)}`;
        }
        static isInteger(number) {
            return number % 1 === 0;
        }
        static strEnumify(obj) {
            return obj;
        }
        static stringToJSFuck(string) {
            return Array
                .from(string)
                .map((character) => {
                return JSFuck_1.JSFuck[character] || character;
            })
                .join(' + ');
        }
        static stringToUnicode(string) {
            const radix = 16;
            let prefix, regexp = new RegExp('[\x00-\x7F]'), template;
            return `'${string.replace(/[\s\S]/g, (escape) => {
                if (regexp.test(escape)) {
                    prefix = '\\x';
                    template = '0'.repeat(2);
                }
                else {
                    prefix = '\\u';
                    template = '0'.repeat(4);
                }
                return `${prefix}${(template + escape.charCodeAt(0).toString(radix)).slice(-template.length)}`;
            })}'`;
        }
    }
    Utils.hexRepetitiveZerosRegExp = new RegExp('^(0{2,})+(?!$)', '');
    Utils.randomGenerator = new chance_1.Chance();
    exports.Utils = Utils;
    //# sourceMappingURL=Utils.js.map