anobis
Version:
JavaScript obfuscator
218 lines (182 loc) • 4.31 kB
text/typescript
import { injectable } from 'inversify';
import {
ArrayUnique,
IsBoolean,
IsArray,
IsIn,
IsNumber,
IsString,
IsUrl,
Min,
Max,
ValidateIf,
validateSync,
ValidationError,
ValidatorOptions
} from 'class-validator';
import { TInputOptions } from '../types/options/TInputOptions';
import { IOptions } from '../interfaces/options/IOptions';
import { TSourceMapMode } from '../types/TSourceMapMode';
import { TStringArrayEncoding } from '../types/options/TStringArrayEncoding';
import { DEFAULT_PRESET } from './presets/Default';
import { OptionsNormalizer } from './OptionsNormalizer';
import { ValidationErrorsFormatter } from './ValidationErrorsFormatter';
()
export class Options implements IOptions {
/**
* @type {ValidatorOptions}
*/
private static validatorOptions: ValidatorOptions = {
validationError: {
target: false
}
};
/**
* @type {boolean}
*/
()
public readonly compact: boolean;
/**
* @type {boolean}
*/
()
public readonly controlFlowFlattening: boolean;
/**
* @type {boolean}
*/
()
(0)
(1)
public readonly controlFlowFlatteningThreshold: number;
/**
* @type {boolean}
*/
()
public readonly deadCodeInjection: boolean;
/**
* @type {number}
*/
()
public readonly deadCodeInjectionThreshold: number;
/**
* @type {boolean}
*/
()
public readonly debugProtection: boolean;
/**
* @type {boolean}
*/
()
public readonly debugProtectionInterval: boolean;
/**
* @type {boolean}
*/
()
public readonly disableConsoleOutput: boolean;
/**
* @type {string[]}
*/
()
()
({
each: true
})
public readonly domainLock: string[];
/**
* @type {boolean}
*/
()
public readonly log: boolean;
/**
* @type {boolean}
*/
()
public readonly mangle: boolean;
/**
* @type {boolean}
*/
()
public readonly renameGlobals: boolean;
/**
* @type {string[]}
*/
()
()
({
each: true
})
public readonly reservedNames: string[];
/**
* @type {boolean}
*/
()
public readonly rotateStringArray: boolean;
/**
* @type {number}
*/
()
public readonly seed: number;
/**
* @type {boolean}
*/
()
public readonly selfDefending: boolean;
/**
* @type {boolean}
*/
()
public readonly sourceMap: boolean;
/**
* @type {string}
*/
()
((options: IOptions) => Boolean(options.sourceMapBaseUrl))
({
require_protocol: true,
require_valid_protocol: true
})
public readonly sourceMapBaseUrl: string;
/**
* @type {string}
*/
()
public readonly sourceMapFileName: string;
/**
* @type {TSourceMapMode}
*/
(['inline', 'separate'])
public readonly sourceMapMode: TSourceMapMode;
/**
* @type {boolean}
*/
()
public readonly stringArray: boolean;
/**
* @type {TStringArrayEncoding}
*/
([true, false, 'base64', 'rc4'])
public readonly stringArrayEncoding: TStringArrayEncoding;
/**
* @type {number}
*/
()
(0)
(1)
public readonly stringArrayThreshold: number;
/**
* @type {boolean}
*/
()
public readonly unicodeEscapeSequence: boolean;
/**
* @param {TInputOptions} inputOptions
*/
constructor (inputOptions: TInputOptions) {
Object.assign(this, DEFAULT_PRESET, inputOptions);
const errors: ValidationError[] = validateSync(this, Options.validatorOptions);
if (errors.length) {
throw new ReferenceError(`Validation failed. errors:\n${ValidationErrorsFormatter.format(errors)}`);
}
Object.assign(this, OptionsNormalizer.normalizeOptions(this));
}
}