JS Beautify

1.15.4 · maintenance · verified Sun Apr 19

JS Beautify is a robust JavaScript library and command-line tool designed for reformatting and re-indenting JavaScript, CSS, and HTML code. It can also unpack and partially deobfuscate scripts processed by common tools like Dean Edward’s packer or `javascript-obfuscator`. The current stable version is 1.15.4, with recent releases addressing compatibility and hotfixes, such as the `polyfill.io` removal and `glob` dependency adjustments for Node.js 18.x. The project distinguishes itself by offering multi-language code formatting and basic de-obfuscation capabilities, which are beyond the scope of many single-purpose formatters. However, the project explicitly states a critical need for new contributors, indicating that existing owners have limited time, which suggests a potentially slower development pace and a maintenance-focused trajectory despite ongoing minor updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `js-beautify` to format JavaScript, CSS, and HTML strings with custom options.

import { js_beautify, css_beautify, html_beautify } from 'js-beautify';

const uglyJavaScript = `
function  myFunction ( a , b ){return a + b  ;}
`;

const uglyCSS = `
body{ margin:0;padding:0;}
`;

const uglyHTML = `
<div><span>Hello</span><p>World</p></div>
`;

const jsOptions = { indent_size: 2, space_in_empty_paren: true, keep_array_indentation: false };
const cssOptions = { indent_size: 4 };
const htmlOptions = { indent_size: 2, wrap_line_length: 80 };

const beautifulJavaScript = js_beautify(uglyJavaScript, jsOptions);
const beautifulCSS = css_beautify(uglyCSS, cssOptions);
const beautifulHTML = html_beautify(uglyHTML, htmlOptions);

console.log('--- Beautiful JavaScript ---\n', beautifulJavaScript);
console.log('--- Beautiful CSS ---\n', beautifulCSS);
console.log('--- Beautiful HTML ---\n', beautifulHTML);

/* Example Output:
-- Beautiful JavaScript ---
 function myFunction (a, b) {
  return a + b;
 }
-- Beautiful CSS ---
 body {
    margin: 0;
    padding: 0;
 }
-- Beautiful HTML ---
 <div>
  <span>Hello</span>
  <p>World</p>
 </div>
*/

view raw JSON →