123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- "use strict";
- import * as esprima from 'esprima';
- import { Obfuscator } from './src/Obfuscator';
- let escodegen = require('escodegen');
- 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, options);
- }
- /**
- * @param astTree
- * @param options
- */
- private static generateCode (astTree: any, options: any = {}): string {
- let escodegenParams: any = Object.assign({}, JavaScriptObfuscator.escodegenParams);
- if (options.hasOwnProperty('compact')) {
- escodegenParams.format.compact = options.compact;
- }
- return escodegen.generate(astTree, escodegenParams);
- }
- }
- module.exports = JavaScriptObfuscator;
|