Socket
Socket
Sign inDemoInstall

terser

Package Overview
Dependencies
0
Maintainers
1
Versions
170
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    terser


Version published
Maintainers
1
Install size
939 B
Created

Package description

What is terser?

The terser npm package is a tool for minifying and compressing JavaScript files. It removes unnecessary whitespace, shortens variable names, and performs various optimizations to reduce the size of your JavaScript files, which can lead to faster load times in web browsers.

What are terser's main functionalities?

Code Minification

Minifies JavaScript code by removing unnecessary characters without changing its functionality.

const Terser = require('terser');

const code = 'function add(x, y) { return x + y; }';
Terser.minify(code).then(result => {
  console.log(result.code); // Output could be 'function add(n,d){return n+d}'
});

Compressing Code

Compresses code by applying various transformations, such as removing unreachable code and simplifying if-statements.

const Terser = require('terser');

const code = 'if (true) { console.log('Hello World!'); }';
const options = { compress: true };
Terser.minify(code, options).then(result => {
  console.log(result.code); // Output could be 'console.log('Hello World!');'
});

Mangling Variable Names

Shortens variable and function names to reduce file size and potentially obfuscate code.

const Terser = require('terser');

const code = 'const longVariableName = 5; console.log(longVariableName);';
const options = { mangle: true };
Terser.minify(code, options).then(result => {
  console.log(result.code); // Output could be something like 'const a=5;console.log(a);'
});

Source Map Support

Generates source maps to help debug minified JavaScript by mapping the minified code back to the original source code.

const Terser = require('terser');

const code = 'function example() { console.log('Hello World!'); }';
const options = {
  sourceMap: {
    filename: 'out.js',
    url: 'out.js.map'
  }
};
Terser.minify(code, options).then(result => {
  console.log(result.code); // Minified code
  console.log(result.map);  // Source map
});

Other packages similar to terser

FAQs

Last updated on 12 May 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc