
Product
A Fresh Look for the Socket Dashboard
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
javascript-obfuscator
Advanced tools
The javascript-obfuscator npm package is a powerful tool for obfuscating JavaScript code, making it difficult for others to read and understand. This is useful for protecting intellectual property, preventing code tampering, and reducing the risk of reverse engineering.
Basic Obfuscation
This feature allows you to obfuscate basic JavaScript code. The example shows how to obfuscate a simple function that logs 'Hello World' to the console.
const JavaScriptObfuscator = require('javascript-obfuscator');
const obfuscatedCode = JavaScriptObfuscator.obfuscate(
`function hello() { console.log('Hello World'); }`,
{ compact: true, controlFlowFlattening: false }
).getObfuscatedCode();
console.log(obfuscatedCode);
Control Flow Flattening
Control Flow Flattening is a feature that makes the control flow of the code less recognizable. The example shows how to enable this option to further obfuscate the 'hello' function.
const JavaScriptObfuscator = require('javascript-obfuscator');
const obfuscatedCode = JavaScriptObfuscator.obfuscate(
`function hello() { console.log('Hello World'); }`,
{ controlFlowFlattening: true }
).getObfuscatedCode();
console.log(obfuscatedCode);
String Array Encoding
String Array Encoding encodes strings in the code to make them harder to read. The example shows how to encode strings using base64 encoding.
const JavaScriptObfuscator = require('javascript-obfuscator');
const obfuscatedCode = JavaScriptObfuscator.obfuscate(
`function hello() { console.log('Hello World'); }`,
{ stringArray: true, stringArrayEncoding: ['base64'] }
).getObfuscatedCode();
console.log(obfuscatedCode);
Self-Defending
The Self-Defending feature makes the obfuscated code more difficult to modify and tamper with. The example shows how to enable this option.
const JavaScriptObfuscator = require('javascript-obfuscator');
const obfuscatedCode = JavaScriptObfuscator.obfuscate(
`function hello() { console.log('Hello World'); }`,
{ selfDefending: true }
).getObfuscatedCode();
console.log(obfuscatedCode);
The obfuscator-io-metro-plugin is a Metro plugin for React Native that uses obfuscator.io to obfuscate JavaScript code. It is specifically designed for React Native projects and integrates seamlessly with the Metro bundler. Compared to javascript-obfuscator, it is more specialized for React Native environments.
UglifyJS is a JavaScript parser, minifier, compressor, and beautifier toolkit. While its primary focus is on minification and compression, it also offers some obfuscation features. Compared to javascript-obfuscator, UglifyJS is more focused on reducing file size and improving performance, with less emphasis on making the code difficult to understand.
#JavaScript obfuscator for Node.js
JavaScript obfuscator for Node.js and free alternative of js-obfuscator without any limits. Compatible with ES6.
###Installation
Install the package with NPM and add it to your devDependencies:
npm install --save-dev javascript-obfuscator
###Usage:
var JavaScriptObfuscator = require('javascript-obfuscator');
var obfuscatedCode = JavaScriptObfuscator.obfuscate(
`var variable = 'abc'; console.log(variable);`,
{
rotateUnicodeArray: false
}
);
console.log(obfuscatedCode);
/*
var _0x41c0 = [
'\u0061\u0062\u0063',
'\u006c\u006f\u0067'
];
var variable = _0x41c0[0];
console[_0x41c0[1]](variable);
*/
###sourceCode
Type: string
Default: null
Any valid SourceCode
###options
Type: Object
Default: null
Options for JavaScript obfuscator:
{
rotateUnicodeArray: false
}
###Available options
####rotateUnicodeArray
Default: true
For more hard understanding of code, during each obfuscation all literal values are stored in array as Unicode codes sequence. This options will rotate all values inside array at random value during obfuscation of code, and insert inside source code helper function which will rotate array values back to their original indexes.
This option affected only on visual code organisation, because we can easily get original array during debug process.
Not recommended for small source code, because helper function will attract attention.
FAQs
JavaScript obfuscator
The npm package javascript-obfuscator receives a total of 299,639 weekly downloads. As such, javascript-obfuscator popularity was classified as popular.
We found that javascript-obfuscator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
Industry Insights
Terry O’Daniel, Head of Security at Amplitude, shares insights on building high-impact security teams, aligning with engineering, and why AI gives defenders a fighting chance.
Security News
MCP spec updated with structured tool output, stronger OAuth 2.1 security, resource indicators, and protocol cleanups for safer, more reliable AI workflows.