All files / src/node-groups StringArrayNodesGroup.ts

100% Statements 23/23
100% Branches 6/6
100% Functions 1/1
100% Lines 22/22
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 79 80 81 82 83 84 85 86 87 88    1x   1x 1x 1x   1x 1x 1x   2588x       2588x         2588x         2588x                     2588x 2065x     523x 508x         15x     523x 523x           523x                             523x 508x                     523x      
import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
 
import { AppendState } from '../enums/AppendState';
 
import { StringArrayCallsWrapper } from '../custom-nodes/string-array-nodes/StringArrayCallsWrapper';
import { StringArrayNode } from '../custom-nodes/string-array-nodes/StringArrayNode';
import { StringArrayRotateFunctionNode } from '../custom-nodes/string-array-nodes/StringArrayRotateFunctionNode';
 
import { AbstractNodesGroup } from './AbstractNodesGroup';
import { StringArray } from '../StringArray';
import { Utils } from '../Utils';
 
export class StringArrayNodesGroup extends AbstractNodesGroup {
    /**
     * @type {AppendState}
     */
    protected appendState: AppendState = AppendState.AfterObfuscation;
 
    /**
     * @type {string}
     */
    private stringArrayName: string = Utils.getRandomVariableName(StringArrayNode.ARRAY_RANDOM_LENGTH);
 
    /**
     * @type {string}
     */
    private stringArrayCallsWrapper: string = Utils.getRandomVariableName(StringArrayNode.ARRAY_RANDOM_LENGTH);
 
    /**
     * @type {number}
     */
    private stringArrayRotateValue: number;
 
    /**
     * @returns {Map<string, ICustomNode> | undefined}
     */
    public getNodes (): Map <string, ICustomNode> | undefined {
        if (!this.options.stringArray) {
            return;
        }
 
        if (this.options.rotateStringArray) {
            this.stringArrayRotateValue = Utils.getRandomGenerator().integer({
                min: 100,
                max: 500
            });
        } else {
            this.stringArrayRotateValue = 0;
        }
 
        const stringArray: StringArray = new StringArray();
        const stringArrayNode: ICustomNode = new StringArrayNode(
            stringArray,
            this.stringArrayName,
            this.stringArrayRotateValue,
            this.options
        );
        const customNodes: Map <string, ICustomNode> = new Map <string, ICustomNode> ([
            [
                'stringArrayNode', stringArrayNode,
            ],
            [
                'stringArrayCallsWrapper',
                new StringArrayCallsWrapper(
                    this.stringArrayCallsWrapper,
                    this.stringArrayName,
                    stringArray,
                    this.options
                )
            ]
        ]);
 
        if (this.options.rotateStringArray) {
            customNodes.set(
                'stringArrayRotateFunctionNode',
                new StringArrayRotateFunctionNode(
                    this.stringArrayName,
                    stringArray,
                    this.stringArrayRotateValue,
                    this.options
                )
            );
        }
 
        return this.syncCustomNodesWithNodesGroup(customNodes);
    }
}