Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uglify-js

Package Overview
Dependencies
Maintainers
3
Versions
288
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uglify-js

JavaScript parser, mangler/compressor and beautifier toolkit

  • 3.19.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25M
decreased by-4.17%
Maintainers
3
Weekly downloads
 
Created

What is uglify-js?

The uglify-js npm package is a JavaScript parser, minifier, compressor, and beautifier toolkit. It is commonly used to reduce the size of JavaScript files by removing unnecessary characters (like whitespace, comments, etc.) without changing their functionality. This helps in decreasing the load time and bandwidth usage of web applications.

What are uglify-js's main functionalities?

Minification

Minification is the process of removing unnecessary characters and whitespace from source code without changing its functionality. The code sample demonstrates how to read a JavaScript file, minify it using uglify-js, and then write the minified code to a new file.

const uglifyJS = require('uglify-js');
const fs = require('fs');

const code = fs.readFileSync('example.js', 'utf8');
const minifiedCode = uglifyJS.minify(code).code;

fs.writeFileSync('example.min.js', minifiedCode);

Compression

Compression is a form of optimization that reduces code size by performing various transformations, such as removing dead code or simplifying expressions. The code sample shows how to use uglify-js to compress a JavaScript file by removing console statements and then writing the compressed code to a new file.

const uglifyJS = require('uglify-js');
const fs = require('fs');

const options = {
  compress: {
    drop_console: true
  }
};

const code = fs.readFileSync('example.js', 'utf8');
const compressedCode = uglifyJS.minify(code, options).code;

fs.writeFileSync('example.compressed.js', compressedCode);

Mangling

Mangling is the process of shortening variable and function names to reduce file size and potentially obfuscate code. The code sample illustrates how to use uglify-js to mangle a JavaScript file and then save the mangled code to a new file.

const uglifyJS = require('uglify-js');
const fs = require('fs');

const options = {
  mangle: true
};

const code = fs.readFileSync('example.js', 'utf8');
const mangledCode = uglifyJS.minify(code, options).code;

fs.writeFileSync('example.mangled.js', mangledCode);

Beautification

Beautification is the process of reformatting minified or obfuscated code into a more readable and maintainable format. The code sample demonstrates how to use uglify-js to beautify a JavaScript file and then write the beautified code to a new file.

const uglifyJS = require('uglify-js');
const fs = require('fs');

const options = {
  output: {
    beautify: true
  }
};

const code = fs.readFileSync('example.js', 'utf8');
const beautifiedCode = uglifyJS.minify(code, options).code;

fs.writeFileSync('example.beautified.js', beautifiedCode);

Other packages similar to uglify-js

Keywords

FAQs

Package last updated on 29 Aug 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc