Files
javascript-obfuscator-javas…/dist/index.js
T
2016-05-31 17:47:51 +03:00

33 lines
1.2 KiB
JavaScript

"use strict";
const esprima = require('esprima');
const escodegen = require('escodegen');
const Obfuscator_1 = require('./src/Obfuscator');
class JavaScriptObfuscator {
static obfuscate(sourceCode, customOptions) {
let astTree = esprima.parse(sourceCode), options = Object.assign(JavaScriptObfuscator.defaultOptions, customOptions), obfuscator = new Obfuscator_1.Obfuscator(options);
obfuscator.obfuscateNode(astTree);
return JavaScriptObfuscator.generateCode(astTree, options);
}
static generateCode(astTree, options) {
let escodegenParams = Object.assign({}, JavaScriptObfuscator.escodegenParams);
if (options.hasOwnProperty('compact')) {
escodegenParams.format = {};
escodegenParams.format.compact = options.compact;
}
return escodegen.generate(astTree, escodegenParams);
}
}
JavaScriptObfuscator.defaultOptions = {
compact: true,
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
encodeUnicodeArray: false,
rotateUnicodeArray: true,
wrapUnicodeArrayCalls: true
};
JavaScriptObfuscator.escodegenParams = {
verbatim: 'x-verbatim-property'
};
module.exports = JavaScriptObfuscator;