merged dev into tests branch

This commit is contained in:
sanex3339
2016-06-16 22:51:29 +03:00
11 changed files with 518 additions and 17 deletions
+18 -6
View File
@@ -1,3 +1,5 @@
import { Chance } from 'chance';
import { JSFuck } from './enums/JSFuck';
export class Utils {
@@ -6,6 +8,11 @@ export class Utils {
*/
private static hexRepetitiveZerosRegExp: RegExp = new RegExp('^(0{2,})+(?!$)', '');
/**
* @type {Chance.Chance}
*/
private static randomGenerator: Chance.Chance = new Chance();
/**
* @param array
* @param searchElement
@@ -65,12 +72,10 @@ export class Utils {
}
/**
* @param min
* @param max
* @returns {number}
* @returns {Chance.Chance}
*/
public static getRandomInteger (min: number, max: number): number {
return Math.round(Math.floor(Math.random() * (max - min + 1)) + min);
public static getRandomGenerator (): Chance.Chance {
return Utils.randomGenerator;
}
/**
@@ -82,7 +87,14 @@ export class Utils {
rangeMaxInteger: number = 99999999,
prefix: string = '_0x';
return `${prefix}${(Utils.decToHex(Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger))).substr(0, length)}`;
return `${prefix}${(
Utils.decToHex(
Utils.getRandomGenerator().integer({
min: rangeMinInteger,
max: rangeMaxInteger
})
)
).substr(0, length)}`;
}
/**
@@ -32,7 +32,10 @@ export class DebugProtectionFunctionNode extends Node {
*/
public appendNode (blockScopeNode: TBlockScopeNode): void {
let programBodyLength: number = blockScopeNode.body.length,
randomIndex: number = Utils.getRandomInteger(0, programBodyLength);
randomIndex: number = Utils.getRandomGenerator().integer({
min: 0,
max: programBodyLength
});
NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), randomIndex);
}
@@ -38,7 +38,10 @@ export class SelfDefendingUnicodeNode extends Node {
randomIndex: number = 0;
if (programBodyLength > 2) {
randomIndex = Utils.getRandomInteger(programBodyLength / 2, programBodyLength - 1);
randomIndex = Utils.getRandomGenerator().integer({
min: programBodyLength / 2,
max: programBodyLength - 1
});
}
NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), randomIndex);
+8 -1
View File
@@ -29,7 +29,14 @@ export class UnicodeArrayNodesGroup extends NodesGroup {
constructor (options: IOptions) {
super(options);
this.unicodeArrayRotateValue = this.options.get('rotateUnicodeArray') ? Utils.getRandomInteger(100, 500) : 0;
if (this.options.get('rotateUnicodeArray')) {
this.unicodeArrayRotateValue = Utils.getRandomGenerator().integer({
min: 100,
max: 500
});
} else {
this.unicodeArrayRotateValue = 0;
}
let unicodeArrayNode: UnicodeArrayNode = new UnicodeArrayNode(
this.unicodeArrayName,