npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

code-obfuscater

v1.0.3

Published

A powerful JavaScript code obfuscator for production builds with irreversible transformations

Readme

code-obfuscater

A powerful JavaScript code obfuscator for production builds with irreversible transformations. This package helps protect your JavaScript code by making it extremely difficult to reverse engineer while maintaining full functionality.

npm version License: MIT

🔗 GitHub Repository: https://github.com/ashrithsathu/code-obfuscater

Features

  • Irreversible Obfuscation: Multiple layers of obfuscation that make code extremely difficult to reverse
  • Multiple Presets: Choose from low, medium, or high obfuscation levels
  • Flexible Input: Support for single files, directories, or glob patterns
  • CLI & API: Use as a command-line tool or import as a library
  • Production Ready: Obfuscated code maintains full functionality
  • Configurable: Customize obfuscation via CLI flags or config files

Installation

Install as a development dependency:

# Using pnpm (recommended)
pnpm add -D code-obfuscater

# Using npm
npm install --save-dev code-obfuscater

# Using yarn
yarn add -D code-obfuscater

Quick Start

Method 1: Using npx (No Installation Required)

You can use the package directly without installing it:

# Obfuscate a single file
npx code-obfuscater obfuscate dist/bundle.js -o dist/bundle.obfuscated.js

# Obfuscate with high security preset
npx code-obfuscater obfuscate dist/bundle.js -p high -o dist/bundle.obfuscated.js

Method 2: Install and Use CLI

After installation, you can use it in your package.json scripts:

{
  "scripts": {
    "build": "webpack",
    "obfuscate": "code-obfuscater obfuscate dist/**/*.js -o dist-obfuscated",
    "build:prod": "npm run build && npm run obfuscate"
  }
}

Then run:

npm run obfuscate

Method 3: Use as a Library

Import and use in your code:

const { obfuscate } = require("code-obfuscater");
// or
import { obfuscate } from "code-obfuscater";

Usage

CLI Usage

Basic Usage

Obfuscate a single file:

# Using npx (recommended for one-time use)
npx code-obfuscater obfuscate dist/bundle.js

# Or if installed locally
code-obfuscater obfuscate dist/bundle.js

Obfuscate multiple files with glob pattern:

npx code-obfuscater obfuscate "dist/**/*.js" -o dist-obfuscated

Options

  • -o, --output <path>: Output directory or file path
  • -p, --preset <preset>: Obfuscation preset (low, medium, high) - default: medium
  • -c, --config <path>: Path to configuration file (JSON)
  • --in-place: Replace input files in place
  • --exclude <pattern>: Glob pattern to exclude files

Examples

Obfuscate with high preset:

npx code-obfuscater obfuscate dist/bundle.js -p high -o dist/bundle.obfuscated.js

Obfuscate entire directory:

npx code-obfuscater obfuscate "dist/**/*.js" -o dist-obfuscated

Obfuscate in place:

npx code-obfuscater obfuscate dist/bundle.js --in-place

Using a config file:

npx code-obfuscater obfuscate dist/bundle.js -c obfuscator.config.json

Programmatic Usage

import { obfuscate, obfuscateFile } from "code-obfuscater";

// Obfuscate code string
const code = `
  function add(a, b) {
    return a + b;
  }
`;

const result = obfuscate(code, { preset: "high" });
console.log(result.obfuscatedCode);

// Obfuscate file
const fileResult = await obfuscateFile("./dist/bundle.js", {
  preset: "medium",
});

Configuration

Presets

  • low: Basic obfuscation with minimal performance impact
  • medium: Balanced obfuscation (default) - good protection with reasonable performance
  • high: Maximum obfuscation - strongest protection, may impact performance

Custom Configuration

Create a JSON config file (obfuscator.config.json):

{
  "preset": "high",
  "compact": true,
  "controlFlowFlattening": true,
  "controlFlowFlatteningThreshold": 0.75,
  "deadCodeInjection": true,
  "deadCodeInjectionThreshold": 0.6,
  "debugProtection": true,
  "debugProtectionInterval": 2000,
  "disableConsoleOutput": true,
  "stringArray": true,
  "stringArrayEncoding": ["base64", "rc4"],
  "stringArrayThreshold": 0.75,
  "transformObjectKeys": true,
  "unicodeEscapeSequence": true
}

Obfuscation Techniques

The package uses multiple obfuscation techniques:

  • Variable/Function Name Mangling: Replaces meaningful names with random identifiers
  • String Encoding: Encodes strings using base64, rc4, or other methods
  • Control Flow Flattening: Restructures control flow to make it harder to follow
  • Dead Code Injection: Adds non-functional code to confuse reverse engineers
  • Self-Defending Code: Protects against debugging and tampering
  • Object Key Transformation: Obfuscates object property names
  • Array/String Shuffling: Randomizes array and string order

Real-World Examples

Example 1: Obfuscate React/Vue Build Output

After building your app, obfuscate the production bundle:

# Build your app first
npm run build

# Then obfuscate the output
npx code-obfuscater obfuscate "dist/**/*.js" -p high -o dist-obfuscated

# Or replace in place
npx code-obfuscater obfuscate "dist/**/*.js" --in-place

Example 2: Obfuscate Node.js Backend Code

# Obfuscate all JS files in your server directory
npx code-obfuscater obfuscate "server/**/*.js" -o server-obfuscated

# Exclude test files
npx code-obfuscater obfuscate "server/**/*.js" --exclude "**/*.test.js" -o server-obfuscated

Example 3: Integration with Build Pipeline

Add to your package.json:

{
  "scripts": {
    "build": "webpack --mode production",
    "obfuscate": "code-obfuscater obfuscate dist/**/*.js -p high -o dist",
    "build:prod": "npm run build && npm run obfuscate"
  }
}

Then run:

npm run build:prod

Example 4: Using in CI/CD Pipeline

# .github/workflows/deploy.yml
- name: Build application
  run: npm run build

- name: Obfuscate code
  run: npx code-obfuscater obfuscate dist/**/*.js -p high -o dist

- name: Deploy
  run: # your deployment command

Example 5: Programmatic Usage in Build Script

Create scripts/obfuscate.js:

const { obfuscateFile } = require("code-obfuscater");
const fs = require("fs").promises;
const path = require("path");

async function obfuscateBuild() {
  const buildDir = path.join(__dirname, "../dist");
  const files = await fs.readdir(buildDir);

  for (const file of files) {
    if (file.endsWith(".js")) {
      const filePath = path.join(buildDir, file);
      const result = await obfuscateFile(filePath, { preset: "high" });
      await fs.writeFile(filePath, result.obfuscatedCode);
      console.log(`Obfuscated ${file}`);
    }
  }
}

obfuscateBuild().catch(console.error);

Run it:

node scripts/obfuscate.js

With Webpack

// webpack.config.js
const { obfuscate } = require("code-obfuscater");

module.exports = {
  // ... your config
  plugins: [
    // ... other plugins
    {
      apply: (compiler) => {
        compiler.hooks.afterEmit.tap("ObfuscatePlugin", async (compilation) => {
          // Obfuscate output files
        });
      },
    },
  ],
};

How is this different from javascript-obfuscator?

code-obfuscater is built on top of javascript-obfuscator and provides a simplified, production-focused wrapper with better developer experience:

Key Differences

1. Built-in CLI Tool

  • javascript-obfuscator: Library only, requires custom CLI setup
  • code-obfuscater: Includes ready-to-use CLI with intuitive commands

2. Preset Configurations

  • javascript-obfuscator: Manual configuration of all options
  • code-obfuscater: Pre-configured presets (low/medium/high) for quick setup

3. File Handling

  • javascript-obfuscator: Works with code strings, requires manual file I/O
  • code-obfuscater: Built-in support for files, directories, and glob patterns

4. Production Defaults

  • javascript-obfuscator: Source maps enabled by default
  • code-obfuscater: Source maps disabled by default for irreversible obfuscation

5. Developer Experience

  • javascript-obfuscator: More configuration options, steeper learning curve
  • code-obfuscater: Simpler API, faster to get started, better for build pipelines

When to Use Each

Use code-obfuscater if:

  • You want a simple CLI tool for production builds
  • You prefer preset configurations over manual setup
  • You need to obfuscate multiple files or directories
  • You want production-ready defaults out of the box

Use javascript-obfuscator directly if:

  • You need fine-grained control over every obfuscation option
  • You're building a custom obfuscation tool
  • You need source maps for debugging
  • You want to integrate with specific build tools that have plugins

Requirements

  • Node.js >= 16.0.0
  • pnpm (recommended) or npm/yarn

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Security Note

While this package provides strong obfuscation, no obfuscation is 100% secure. Determined attackers with enough time and resources may still be able to reverse engineer obfuscated code. Use obfuscation as one layer of your security strategy, not the only one.