forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
44 lines (35 loc) · 1.06 KB
/
index.ts
File metadata and controls
44 lines (35 loc) · 1.06 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
"use strict";
declare let module: any;
import { Obfuscator } from './src/Obfuscator';
import { UnicodeArrayNodesGroup } from './src/node-groups/UnicodeArrayNodesGroup';
import { Utils } from './src/Utils';
let escodegen = require('escodegen'),
esprima = require('esprima');
export class JavaScriptObfuscator {
/**
* @type any
*/
private static escodegenParams: any = {
format: {
//compact: true
},
verbatim: 'x-verbatim-property'
};
/**
* @param sourceCode
* @param options
*/
public static obfuscate (sourceCode: string, options: any): string {
let astTree: any = esprima.parse(sourceCode),
obfuscator: Obfuscator = new Obfuscator(options);
obfuscator.obfuscateNode(astTree);
return JavaScriptObfuscator.generateCode(astTree);
}
/**
* @param astTree
*/
private static generateCode (astTree: any): string {
return escodegen.generate(astTree, JavaScriptObfuscator.escodegenParams);
}
}
module.exports = JavaScriptObfuscator;