dev.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
  3. (function () {
  4. const JavaScriptObfuscator: any = require('../../index');
  5. let obfuscationResult = JavaScriptObfuscator.obfuscate(
  6. `
  7. const isTrue = something => !!(something?.bob || something?.sally);
  8. const throwsError = () => {
  9. throw new Error("Should not be here!");
  10. };
  11. const myFunction2 = () => {
  12. return isTrue() ? { my: "object", nested: { anotherParam: new throwsError() } } : "The only place we should be";
  13. };
  14. console.log(myFunction2());
  15. `,
  16. {
  17. ...NO_ADDITIONAL_NODES_PRESET,
  18. compact: false,
  19. simplify: false,
  20. transformObjectKeys: true,
  21. identifierNamesGenerator: 'mangled'
  22. }
  23. );
  24. let obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
  25. let identifierNamesCache = obfuscationResult.getIdentifierNamesCache();
  26. console.log(obfuscatedCode);
  27. console.log(eval(obfuscatedCode));
  28. console.log(identifierNamesCache);
  29. })();