mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
33 lines
1.2 KiB
JavaScript
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;
|