Registry / serialization / js-beautify

js-beautify

JSON →
library1.15.4jsnpmunverified

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.

npm install js-beautify
INSTALL
IMPORT
SIG · JS-BEAUTIFY
J
js-beautify
serializationjavascriptv1.15.4
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

js_beautify
✓ import { js_beautify } from 'js-beautify';
✗ import beautify from 'js-beautify'; const beautify = require('js-beautify');
The primary JavaScript beautifier function is a named export. For CommonJS, use `require('js-beautify').js_beautify`.
css_beautify
✓ import { css_beautify } from 'js-beautify';
✗ const cssBeautify = require('js-beautify').css;
For CSS, `css_beautify` is a named export. Older CommonJS examples might show `require('js-beautify').css` but the `_beautify` suffix is standard.
html_beautify
✓ import { html_beautify } from 'js-beautify';
✗ const htmlBeautify = require('js-beautify').html;
Similar to CSS, `html_beautify` is the named export. Older CommonJS usage might use `require('js-beautify').html`.

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> */
js-beautify --version
Debug
Known issues
gotchaThe `js-beautify` project is actively seeking new contributors due to limited time from existing maintainers. This could impact future development, bug fixes, and feature additions, suggesting a reliance on community contributions for its long-term vitality.
fix
Consider contributing to the project if you rely on it heavily, or be aware of potential slower updates and community-driven support.
affects: >=1.0.0
breakingVersion 1.15.1 included a hotfix to remove `polyfill.io` usage. If your projects were relying on older versions of `js-beautify` that implicitly used `polyfill.io`, this change might have impacted script loading or functionality if `polyfill.io` became unavailable or changed its behavior.
fix
Update to `js-beautify` v1.15.1 or newer to avoid `polyfill.io` dependency. Ensure your environment provides necessary polyfills if any were implicitly consumed via `polyfill.io` in older versions.
affects: <1.15.1
gotchaVersion 1.15.3 downgraded the `glob` dependency to v10.x to ensure compatibility with Node.js 18.x. Users on specific Node.js or `glob` versions might have encountered compatibility issues with earlier `js-beautify` releases that used newer `glob` versions.
fix
Upgrade to `js-beautify` v1.15.3 or later to ensure compatibility with Node.js 18.x, as the `glob` dependency has been adjusted for broader support.
affects: >=1.15.0 <1.15.3
Errors
Common errors & fixes
TypeError: js_beautify is not a function
Attempting to import `beautify` as a default export or using `require('js-beautify')` directly without specifying `js_beautify` when the library primarily uses named exports.
fix
Use named imports: `import { js_beautify } from 'js-beautify';` for ESM, or `const { js_beautify } = require('js-beautify');` for CommonJS. Alternatively, for CommonJS, `const js_beautify = require('js-beautify').js_beautify;`.
SyntaxError: Cannot use import statement outside a module
Using `import` syntax in a Node.js CommonJS module (e.g., in a `.js` file without `"type": "module"` in `package.json`).
fix
Either convert your project or file to an ESM module by adding `"type": "module"` to your `package.json` or changing file extension to `.mjs`, or use CommonJS `require()` syntax: `const { js_beautify } = require('js-beautify');`.
js-beautify isn't correctly formatting simple html
Attempting to use `js_beautify` function for HTML code, or not providing appropriate HTML-specific options.
fix
Ensure you are using the correct beautifier function for the specific language: `html_beautify` for HTML and `css_beautify` for CSS. Pass relevant options for the chosen beautifier, as their options sets may differ.
Upgrade
Version history
1.15.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Anthropic
1
Resources
js-beautify — npm install js-beautify · libregistry