{"id":11150,"library":"js-beautify","title":"JS Beautify","description":"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.","status":"maintenance","version":"1.15.4","language":"javascript","source_language":"en","source_url":"git://github.com/beautifier/js-beautify","tags":["javascript","beautify","beautifier","code-quality"],"install":[{"cmd":"npm install js-beautify","lang":"bash","label":"npm"},{"cmd":"yarn add js-beautify","lang":"bash","label":"yarn"},{"cmd":"pnpm add js-beautify","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary JavaScript beautifier function is a named export. For CommonJS, use `require('js-beautify').js_beautify`.","wrong":"import beautify from 'js-beautify';\nconst beautify = require('js-beautify');","symbol":"js_beautify","correct":"import { js_beautify } from 'js-beautify';"},{"note":"For CSS, `css_beautify` is a named export. Older CommonJS examples might show `require('js-beautify').css` but the `_beautify` suffix is standard.","wrong":"const cssBeautify = require('js-beautify').css;","symbol":"css_beautify","correct":"import { css_beautify } from 'js-beautify';"},{"note":"Similar to CSS, `html_beautify` is the named export. Older CommonJS usage might use `require('js-beautify').html`.","wrong":"const htmlBeautify = require('js-beautify').html;","symbol":"html_beautify","correct":"import { html_beautify } from 'js-beautify';"}],"quickstart":{"code":"import { js_beautify, css_beautify, html_beautify } from 'js-beautify';\n\nconst uglyJavaScript = `\nfunction  myFunction ( a , b ){return a + b  ;}\n`;\n\nconst uglyCSS = `\nbody{ margin:0;padding:0;}\n`;\n\nconst uglyHTML = `\n<div><span>Hello</span><p>World</p></div>\n`;\n\nconst jsOptions = { indent_size: 2, space_in_empty_paren: true, keep_array_indentation: false };\nconst cssOptions = { indent_size: 4 };\nconst htmlOptions = { indent_size: 2, wrap_line_length: 80 };\n\nconst beautifulJavaScript = js_beautify(uglyJavaScript, jsOptions);\nconst beautifulCSS = css_beautify(uglyCSS, cssOptions);\nconst beautifulHTML = html_beautify(uglyHTML, htmlOptions);\n\nconsole.log('--- Beautiful JavaScript ---\\n', beautifulJavaScript);\nconsole.log('--- Beautiful CSS ---\\n', beautifulCSS);\nconsole.log('--- Beautiful HTML ---\\n', beautifulHTML);\n\n/* Example Output:\n-- Beautiful JavaScript ---\n function myFunction (a, b) {\n  return a + b;\n }\n-- Beautiful CSS ---\n body {\n    margin: 0;\n    padding: 0;\n }\n-- Beautiful HTML ---\n <div>\n  <span>Hello</span>\n  <p>World</p>\n </div>\n*/","lang":"javascript","description":"This quickstart demonstrates how to use `js-beautify` to format JavaScript, CSS, and HTML strings with custom options."},"warnings":[{"fix":"Consider contributing to the project if you rely on it heavily, or be aware of potential slower updates and community-driven support.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Version 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.","severity":"breaking","affected_versions":"<1.15.1"},{"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.","message":"Version 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.","severity":"gotcha","affected_versions":">=1.15.0 <1.15.3"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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;`.","cause":"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.","error":"TypeError: js_beautify is not a function"},{"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');`.","cause":"Using `import` syntax in a Node.js CommonJS module (e.g., in a `.js` file without `\"type\": \"module\"` in `package.json`).","error":"SyntaxError: Cannot use import statement outside a module"},{"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.","cause":"Attempting to use `js_beautify` function for HTML code, or not providing appropriate HTML-specific options.","error":"js-beautify isn't correctly formatting simple html"}],"ecosystem":"npm"}