forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.ts
More file actions
217 lines (182 loc) · 4.21 KB
/
Options.ts
File metadata and controls
217 lines (182 loc) · 4.21 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
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';
@injectable()
export class Options implements IOptions {
/**
* @type {ValidatorOptions}
*/
private static validatorOptions: ValidatorOptions = {
validationError: {
target: false
}
};
/**
* @type {boolean}
*/
@IsBoolean()
public readonly compact: boolean;
/**
* @type {boolean}
*/
@IsBoolean()
public readonly controlFlowFlattening: boolean;
/**
* @type {boolean}
*/
@IsNumber()
@Min(0)
@Max(1)
public readonly controlFlowFlatteningThreshold: number;
/**
* @type {boolean}
*/
@IsBoolean()
public readonly deadCodeInjection: boolean;
/**
* @type {number}
*/
@IsNumber()
public readonly deadCodeInjectionThreshold: number;
/**
* @type {boolean}
*/
@IsBoolean()
public readonly debugProtection: boolean;
/**
* @type {boolean}
*/
@IsBoolean()
public readonly debugProtectionInterval: boolean;
/**
* @type {boolean}
*/
@IsBoolean()
public readonly disableConsoleOutput: boolean;
/**
* @type {string[]}
*/
@IsArray()
@ArrayUnique()
@IsString({
each: true
})
public readonly domainLock: string[];
/**
* @type {boolean}
*/
@IsBoolean()
public readonly log: boolean;
/**
* @type {boolean}
*/
@IsBoolean()
public readonly mangle: boolean;
/**
* @type {boolean}
*/
@IsBoolean()
public readonly renameGlobals: boolean;
/**
* @type {string[]}
*/
@IsArray()
@ArrayUnique()
@IsString({
each: true
})
public readonly reservedNames: string[];
/**
* @type {boolean}
*/
@IsBoolean()
public readonly rotateStringArray: boolean;
/**
* @type {number}
*/
@IsNumber()
public readonly seed: number;
/**
* @type {boolean}
*/
@IsBoolean()
public readonly selfDefending: boolean;
/**
* @type {boolean}
*/
@IsBoolean()
public readonly sourceMap: boolean;
/**
* @type {string}
*/
@IsString()
@ValidateIf((options: IOptions) => Boolean(options.sourceMapBaseUrl))
@IsUrl({
require_protocol: true,
require_valid_protocol: true
})
public readonly sourceMapBaseUrl: string;
/**
* @type {string}
*/
@IsString()
public readonly sourceMapFileName: string;
/**
* @type {TSourceMapMode}
*/
@IsIn(['inline', 'separate'])
public readonly sourceMapMode: TSourceMapMode;
/**
* @type {boolean}
*/
@IsBoolean()
public readonly stringArray: boolean;
/**
* @type {TStringArrayEncoding}
*/
@IsIn([true, false, 'base64', 'rc4'])
public readonly stringArrayEncoding: TStringArrayEncoding;
/**
* @type {number}
*/
@IsNumber()
@Min(0)
@Max(1)
public readonly stringArrayThreshold: number;
/**
* @type {boolean}
*/
@IsBoolean()
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));
}
}