index.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. RawSource: any = require('webpack-core/lib/RawSource');
  9. export class JavaScriptObfuscator {
  10. /**
  11. * @type any
  12. */
  13. private static escodegenParams: any = {
  14. format: {
  15. //compact: true
  16. },
  17. verbatim: 'x-verbatim-property'
  18. };
  19. /**
  20. * @param sourceCode
  21. * @param options
  22. */
  23. public static obfuscate (sourceCode: string, options: any): string {
  24. let astTree: any = esprima.parse(sourceCode),
  25. obfuscator: Obfuscator = new Obfuscator(options);
  26. obfuscator.obfuscateNode(astTree);
  27. return JavaScriptObfuscator.generateCode(astTree);
  28. }
  29. /**
  30. * @param astTree
  31. */
  32. private static generateCode (astTree: any): string {
  33. return new RawSource(escodegen.generate(astTree, JavaScriptObfuscator.escodegenParams));
  34. }
  35. }
  36. module.exports = JavaScriptObfuscator;