index.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. declare let module: any;
  3. import { Obfuscator } from './src/Obfuscator';
  4. import { UnicodeArrayNodesGroup } from './src/node-groups/UnicodeArrayNodesGroup';
  5. import { Utils } from './src/Utils';
  6. let escodegen = require('escodegen'),
  7. esprima = require('esprima');
  8. export class JavaScriptObfuscator {
  9. /**
  10. * @type any
  11. */
  12. private static escodegenParams: any = {
  13. format: {
  14. //compact: true
  15. },
  16. verbatim: 'x-verbatim-property'
  17. };
  18. /**
  19. * @param sourceCode
  20. * @param options
  21. */
  22. public static obfuscate (sourceCode: string, options: any): string {
  23. let astTree: any = esprima.parse(sourceCode),
  24. obfuscator: Obfuscator = new Obfuscator(options);
  25. obfuscator.obfuscateNode(astTree);
  26. return JavaScriptObfuscator.generateCode(astTree);
  27. }
  28. /**
  29. * @param astTree
  30. */
  31. private static generateCode (astTree: any): string {
  32. return escodegen.generate(astTree, JavaScriptObfuscator.escodegenParams);
  33. }
  34. }
  35. module.exports = JavaScriptObfuscator;