Developer ٹول اپ ڈیٹ کیا گیا 2 دن قبل

Free JavaScript (JS) Formatter Online

JavaScript Beautify adds indentation and line breaks to a compact script so you can read it again. It works well on classic ES5 code, but it is not safe for every modern syntax feature; test the output before using it. Paste code or fetch a URL, then copy or download the result.

JS Formatter Beautify JS Readable Code Online Formatter

استعمال کریں Free JavaScript (JS) Formatter Online

ایڈیٹر میں اس کا مواد لوڈ کرنے کے لیے براہِ راست کوڈ فائل کا یو آر ایل درج کریں۔

خروج

ہو گیا
ٹول لنک
کلپ بورڈ پر کاپی ہو گیا۔
اس ٹول کو بہتر بنانے میں مدد کریں
68
استعمال شدہ وقت
70
کل صارفین
5+ سال
پیش کیا گیا
آخری بار جائزہ لیا گیا۔ استعمال کے اعداد و شمار کو دورانیہ وار آڈٹس کے دوران تازہ کاری کی جاتی 2 ہفتے قبلہے۔ (رپورٹنگ سے21 Feb 2022)
مطابقت نہ ہونے کی اطلاع دیں

مواد پڑھیں

سیکھیں کہ یہ آلہ کیسے کام کرتا ہے اور اسے کب استعمال کرنا ہے۔

What this page is for

A minified script is one dense block of code. This page runs the source through a bundled JavaScript beautifier, which inserts line breaks, indents nested blocks with four spaces and spaces out operators. Comments are kept. The result is a readable copy that you can inspect, review or use as a starting point for a repair.

The page opens with JavaScript and Beautify already selected and accepts up to 200,000 characters per run. The beautifier is a legacy, ES5-oriented implementation, and that limitation matters. Read the section on modern syntax before you run it on a current codebase.

How the beautifier works

The script is tokenised and reprinted according to a set of formatting rules. Blocks such as functions, if statements, loops and classes receive a new line and an extra level of indentation. Operators receive surrounding spaces. A closing brace returns to the previous level. The output uses four spaces per level and does not add semicolons that were missing from the input.

Because it is a reprint rather than a parse-and-compile pass, it does not rename identifiers or evaluate expressions. It also does not check that the result is valid JavaScript. That is why the output must be tested, especially when the input uses syntax newer than the beautifier.

What it handles well

Classic function declarations, if/else chains, for and while loops, object literals, arrays, try/catch blocks and constructor functions all format predictably. Class declarations with fields and methods also format in testing. Line comments and block comments are preserved, which makes the output useful for understanding an unfamiliar vendor file.

A typical ES5 function comes back with the body indented, each statement on its own line and the braces aligned. That is enough to trace control flow and find a missing branch.

Where modern syntax breaks

This is the most important limitation on the page. The bundled beautifier does not understand several features that are common in modern JavaScript, and it can split their tokens into invalid code:

  • Arrow functions: the arrow token can be separated into an equals sign and a greater-than sign, which is not valid syntax.
  • Optional chaining: the question mark and dot can be separated by a space, changing the operator into something the engine rejects.
  • Nullish coalescing: the two question marks can be separated, with the same effect.
  • Template literals: an interpolation can be broken across lines and spaces, corrupting the string.

These are not cosmetic differences. The output may look plausible at a glance and still fail to parse. If the script contains any of these features, do not replace the original with the beautified copy. Use an editor or formatter that supports the syntax, and treat this page as unsuitable for that file.

JSX and TypeScript

JSX and TypeScript are not JavaScript. Angle-bracket components, type annotations, interfaces and generics use syntax the beautifier does not model. It may format parts of the file and corrupt others. Compile or strip the types first, or use a formatter built for those languages.

Comments are kept

Line comments and block comments survive the pass in testing, including a comment at the top of the file and a block comment at the end. That is useful when you are reading a vendored library and the license or explanation matters. It also means the output is not a minified file; it is a reading copy.

What it does not change

Identifiers, string contents, numeric literals and the presence or absence of semicolons are left alone. The beautifier does not add missing semicolons, remove dead branches, rename variables or convert syntax. If the input is already valid, the output should be the same program with different whitespace, provided the syntax is supported.

When to use it

Use it on an older vendor script that you need to inspect. Use it on a small ES5 file you inherited and want to step through. Use it when a stack trace points to a compact file and you need line breaks to find the relevant block. Do not use it as a commit-time formatter for a modern application, and do not use it on a file you cannot restore from version control.

Step by step

  1. Keep a copy of the original file. This is not optional when modern syntax may be present.
  2. Paste the script into Manual Code, or load it through the URL tab.
  3. Confirm the language is JavaScript and the mode is Beautify.
  4. Press Process Code.
  5. Scan the output for split operators, broken template strings and stray spaces before replacing anything.
  6. Copy the result, or download it as beautify-output.js.
  7. Run the output through a syntax check before using it.

Fetching a script from a URL

The URL tab downloads a public script on the server and places the response in the editor. The fetch is capped at 200,000 characters. CDN links usually work; authenticated or bot-protected links usually do not. The server fetches the raw response, so an HTML error page will fail to format as JavaScript.

Checking the output

The quickest check is a syntax parser. Save the output as a .js file and run it through Node with the check flag, or paste it into a browser console inside a try block. A parse error tells you the beautifier broke the file. If it parses, compare the behaviour with the original on a test page; formatting should not change behaviour, but token splitting can change meaning before it changes syntax.

Working from a stack trace

A production stack trace gives a line and column in a compact file. After beautifying, the line numbers change, so use the column and the surrounding tokens to find the frame. Search for a distinctive string from the trace, such as an error message or a function name that survived minification. This minifier does not rename identifiers, so a function name from the trace is usually still searchable. Once you find the block, read upward to see which branch called it.

Formatting a fragment

You do not have to paste the whole bundle. If you only need to read one function, copy that function plus any helper it calls into the editor. A smaller input is easier to check and less likely to hit an unsupported construct. Keep the fragment in a scratch file and never paste the formatted fragment back into the bundle.

Limits

One script per run, 200,000 characters, JavaScript mode on this page. Processing happens on the server and the result is returned; it is not stored. The tool does not lint, type-check, transpile or guarantee that the output is valid for modern engines.

Frequently Asked Questions

اکثر پوچھے جانے والے سوالات

صارفین کے ان سوالات کے مختصر جوابات جو وہ نتیجے پر بھروسہ کرنے سے پہلے پوچھتے ہیں۔

The bundled beautifier is ES5-oriented and can split the arrow token. Keep the original and use a modern formatter for files that use arrow functions.

No. It can separate the question mark and dot, producing invalid code. Do not use the output on a script that relies on optional chaining.

Yes. Line and block comments survived in testing, which makes the output useful for reading vendor code.

No. It reprints the tokens and does not insert semicolons. If the input relied on automatic semicolon insertion, the output keeps the same structure.

No. Those languages use syntax the beautifier does not understand. Compile them first or use a language-specific formatter.

Only after a syntax check and a behaviour comparison. For modern syntax the answer is usually no; for ES5 code it is usually yes.

It is sent to the server for formatting and returned in the response. The tool does not store it.

تبصرے (0)

صارفین کے تبادلہ خیال، غیر معمولی صورتوں، اور مزید رہنمائی کے لیے نکات۔
تبصرہ کریں
آپ کا تبصرہ جمع کروانے کے بعد عوامی طور پر ظاہر ہوگا۔
ابھی تک کوئی تبصرہ نہیں۔ پہلا تبصرہ کریں!
ہمیں بتائیں!
اس ٹول کے ساتھ کسی مسئلے کی رپورٹ کریں

براہ کرم آپ کو درپیش مسئلے کی وضاحت کریں تاکہ ہم اس کی تحقیقات کر سکیں اور ٹول کو بہتر بنا سکیں۔

سب سے زیادہ مدد کیا کرتا ہے
ان پٹ، متوقع نتیجہ، حقیقی نتیجہ، براؤزر/ڈیوائس، اور جب مددگار ہو تو اسکرین شاٹ شامل کریں۔
اسکرین شاٹ بٹن براؤزر میں موجود صفحے کی تصویر لیتا ہے اور اس فارم کے ساتھ پیدا شدہ تصویر منسلک کرتا ہے۔
پورے صفحے کا اسکرین شاٹ
آپ کے براؤزر میں newisty کے ساتھ محفوظ کیا گیا۔
ابھی تک کوئی اسکرین شاٹ نہیں لیا گیا۔
اوزار رپورٹ