mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
86 lines
2.1 KiB
TypeScript
86 lines
2.1 KiB
TypeScript
import { injectable, inject } from 'inversify';
|
|
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
|
|
|
|
import * as format from 'string-template';
|
|
|
|
import { TStatement } from '../../types/node/TStatement';
|
|
|
|
import { IOptions } from '../../interfaces/options/IOptions';
|
|
import { IStorage } from '../../interfaces/storages/IStorage';
|
|
|
|
import { initializable } from '../../decorators/Initializable';
|
|
|
|
import { StringArrayTemplate } from '../../templates/custom-nodes/string-array-nodes/string-array-node/StringArrayTemplate';
|
|
|
|
import { AbstractCustomNode } from '../AbstractCustomNode';
|
|
import { StringArrayStorage } from '../../storages/string-array/StringArrayStorage';
|
|
|
|
@injectable()
|
|
export class StringArrayNode extends AbstractCustomNode {
|
|
/**
|
|
* @type {number}
|
|
*/
|
|
public static ARRAY_RANDOM_LENGTH: number = 4;
|
|
|
|
/**
|
|
* @type {IStorage <string>}
|
|
*/
|
|
@initializable()
|
|
private stringArray: IStorage <string>;
|
|
|
|
/**
|
|
* @type {string}
|
|
*/
|
|
@initializable()
|
|
private stringArrayName: string;
|
|
|
|
/**
|
|
* @type {number}
|
|
*/
|
|
@initializable()
|
|
private stringArrayRotateValue: number;
|
|
|
|
/**
|
|
* @param options
|
|
*/
|
|
constructor (
|
|
@inject(ServiceIdentifiers.IOptions) options: IOptions
|
|
) {
|
|
super(options);
|
|
}
|
|
|
|
/**
|
|
* @param stringArray
|
|
* @param stringArrayName
|
|
* @param stringArrayRotateValue
|
|
*/
|
|
public initialize (
|
|
stringArray: IStorage <string>,
|
|
stringArrayName: string,
|
|
stringArrayRotateValue: number
|
|
): void {
|
|
this.stringArray = stringArray;
|
|
this.stringArrayName = stringArrayName;
|
|
this.stringArrayRotateValue = stringArrayRotateValue;
|
|
}
|
|
|
|
/**
|
|
* @returns {string}
|
|
*/
|
|
public getCode (): string {
|
|
return format(StringArrayTemplate(), {
|
|
stringArrayName: this.stringArrayName,
|
|
stringArray: this.stringArray.toString()
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @returns {TStatement[]}
|
|
*/
|
|
public getNode (): TStatement[] {
|
|
(<StringArrayStorage>this.stringArray).rotateArray(this.stringArrayRotateValue);
|
|
|
|
return super.getNode();
|
|
}
|
|
}
|