Install gulp-obfuscate via npm
masterInstall gulp-obfuscate as a development dependency using npm.
$ npm install --save-dev gulp-obfuscaterepository·master·Indexed 18 days ago
https://github.com/mikrofusion/gulp-obfuscateA Gulp plugin for obfuscating JavaScript code by replacing variable, function, and object property names with visually confusing characters. It supports multiple styles, including LOOK_OF_DISAPPROVAL and ZALGO, and allows for the exclusion of specific patterns or reserved words to maintain interface compatibility.
Install gulp-obfuscate as a development dependency using npm.
$ npm install --save-dev gulp-obfuscateUse the exclude option to prevent certain strings or regular expressions from being obfuscated. This is useful for maintaining names for interfaces or external code dependencies.
Note: The default list of JavaScript reserved words and special characters is automatically appended to any values you provide in options.exclude.
To use the plugin, require gulp-obfuscate and pipe your source files through the obfuscate() function within a Gulp task.
var gulp = require('gulp');
var obfuscate = require('gulp-obfuscate');
gulp.task('default', function () {
return gulp.src('test.js')
.pipe(obfuscate());
});The obfuscate(options) function accepts an options object to customize the obfuscation style. You can choose between LOOK_OF_DISAPPROVAL (default) and ZALGO styles. Both methods produce valid ECMAScript 5.1 variables, but ZALGO may not be supported by older browsers.
obfuscate = require('gulp-obfuscate');
...
.pipe(obfuscate({ replaceMethod: obfuscate.ZALGO }))
...The following configuration keys are available for the obfuscate(options) method:
// options.replaceMethod
// Type: ZALGO | LOOK_OF_DISAPPROVAL
// Default: 'LOOK_OF_DISAPPROVAL'
// options.exclude
// Type: String | Array of Strings
// Default: 'break', 'case', 'catch', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'finally', 'for', 'function', 'if', 'in', 'instanceof', 'new', 'return', 'switch', 'this', 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with', 'prototype', 'null', 'true', 'false', 'NaN', 'undefined', 'Infinity', 'ಠ_ಠ', 'H͇̬͔̳̖̅̒ͥͧẸ̖͇͈͍̱̭̌͂͆͊_C͈OM̱̈́͛̈ͩ͐͊ͦEͨ̓̐S̬̘͍͕͔͊̆̑̈́̅'The gulpObfuscate(options) function is the primary entrypoint for the plugin. It obfuscates variable names, function names, and object properties by replacing them with a specific string pattern.
| Option | Type | Default | Description |
|---|---|---|---|
exclude | Array | gulpObfuscate.defaultExclude | A list of strings (regex patterns or literal names) to exclude from obfuscation. |
replaceMethod | Number | gulpObfuscate.LOOK_OF_DISAPPROVAL | Determines the character set used for the obfuscated names. |
debug | Boolean | false | If true, logs the conversion mapping (e.g., original <-> obfuscated) to the console using gulp-util. |
gulpObfuscate.LOOK_OF_DISAPPROVAL (Value: 1): Uses the string ಠ_ಠ.gulpObfuscate.ZALGO (Value: 0): Uses a Zalgo-style string: H͇̬͔̳̖̅̒ͥͧẸ̖͇͈͍̱̭̌͂͆͊_C͈OM̱̈́͛̈ͩ͐͊ͦEͨ̓̐S̬̘͍͕͔͊̆̑̈́̅.const gulpObfuscate = require('gulp-obfuscate');
// Basic usage
gulp.task('obfuscate', () => {
return gulp.src('src/**/*.js')
.pipe(gulpObfuscate({
exclude: ['importantVar', 'apiEndpoint'],
replaceMethod: gulpObfuscate.ZALGO,
debug: true
}))
.pipe(gulp.dest('dist'));
});The gulpObfuscate.init() method resets the plugin's internal state. While init() is called automatically upon requiring the module, you can call it manually to reset seeds or configuration constants.
When init() is called, the following properties are set:
gulpObfuscate.nameHash: An object used to track the mapping between original names and obfuscated names to ensure consistency within a single run.gulpObfuscate.seed: A random integer between minSeed and maxSeed used to generate unique obfuscated names.gulpObfuscate.minSeed: The minimum value for the random seed (default: 1).gulpObfuscate.maxSeed: The maximum value for the random seed (default: 999).gulpObfuscate.defaultExclude: An array of reserved keywords and strings that are automatically excluded from obfuscation (e.g., var, function, this, null, true, false, undefined, NaN, Infinity, and the obfuscation strings themselves).gulpObfuscate.ZALGO: Constant 0.gulpObfuscate.LOOK_OF_DISAPPROVAL: Constant 1.