mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
"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; |