voluptasvelit
Version:
JavaScript obfuscator
264 lines (223 loc) • 5.84 kB
text/typescript
import { inject, injectable } from 'inversify';
import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
import {
ArrayUnique,
IsArray,
IsBoolean,
IsIn,
IsNumber,
IsString,
IsUrl,
Max,
Min,
ValidateIf,
validateSync,
ValidationError,
ValidatorOptions
} from 'class-validator';
import { TInputOptions } from '../types/options/TInputOptions';
import { TStringArrayEncoding } from '../types/options/TStringArrayEncoding';
import { IOptions } from '../interfaces/options/IOptions';
import { IOptionsNormalizer } from '../interfaces/options/IOptionsNormalizer';
import { IdentifierNamesGenerator } from '../enums/generators/identifier-names-generators/IdentifierNamesGenerator';
import { ObfuscationTarget } from '../enums/ObfuscationTarget';
import { SourceMapMode } from '../enums/source-map/SourceMapMode';
import { StringArrayEncoding } from '../enums/StringArrayEncoding';
import { DEFAULT_PRESET } from './presets/Default';
import { ValidationErrorsFormatter } from './ValidationErrorsFormatter';
()
export class Options implements IOptions {
/**
* @type {ValidatorOptions}
*/
private static readonly 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 {IdentifierNamesGenerator}
*/
([
IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
IdentifierNamesGenerator.MangledIdentifierNamesGenerator
])
public readonly identifierNamesGenerator!: IdentifierNamesGenerator;
/**
* @type {string}
*/
()
public readonly identifiersPrefix!: string;
/**
* @type {string}
*/
()
public readonly inputFileName!: string;
/**
* @type {boolean}
*/
()
public readonly log!: boolean;
/**
* @type {boolean}
*/
()
public readonly renameGlobals!: boolean;
/**
* @type {string[]}
*/
()
()
({
each: true
})
public readonly reservedNames!: string[];
/**
* @type {string[]}
*/
()
()
({
each: true
})
public readonly reservedStrings!: 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_tld: false,
require_valid_protocol: true
})
public readonly sourceMapBaseUrl!: string;
/**
* @type {string}
*/
()
public readonly sourceMapFileName!: string;
/**
* @type {SourceMapMode}
*/
([SourceMapMode.Inline, SourceMapMode.Separate])
public readonly sourceMapMode!: SourceMapMode;
/**
* @type {boolean}
*/
()
public readonly stringArray!: boolean;
/**
* @type {TStringArrayEncoding}
*/
([true, false, StringArrayEncoding.Base64, StringArrayEncoding.Rc4])
public readonly stringArrayEncoding!: TStringArrayEncoding;
/**
* @type {number}
*/
()
(0)
(1)
public readonly stringArrayThreshold!: number;
/**
* @type {ObfuscationTarget}
*/
([ObfuscationTarget.Browser, ObfuscationTarget.BrowserNoEval, ObfuscationTarget.Node])
public readonly target!: ObfuscationTarget;
/**
* @type {boolean}
*/
()
public readonly transformObjectKeys!: boolean;
/**
* @type {boolean}
*/
()
public readonly unicodeEscapeSequence!: boolean;
/**
* @param {TInputOptions} inputOptions
* @param {IOptionsNormalizer} optionsNormalizer
*/
constructor (
(ServiceIdentifiers.TInputOptions) inputOptions: TInputOptions,
(ServiceIdentifiers.IOptionsNormalizer) optionsNormalizer: IOptionsNormalizer
) {
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.normalize(this));
}
}