Skip to main content
CaseSwitch

JavaScript Formatter

Use the CaseSwitch JavaScript Formatter to pretty-print a minified snippet or one-line function so it is readable for review. Paste the code, copy the formatted result. Formatting runs in this browser via Prettier’s Babel parser — nothing is uploaded.

Written by the CaseSwitch editorial team. We maintain these tools in the browser so drafts, keys, and images stay on your device.

Last reviewed: 23 July 2026

Processed locally in your browser. Nothing is sent to a server.

Paste or type text to convert. Output stays empty until there is input.

Character count: 0 · Word count: 0 · Line count: 0

Examples

Expand a one-line function

Input

function add(a,b){return a+b}

Output

function add(a, b) {
  return a + b;
}

Minify a pretty function

Input

function add(a, b) {
  return a + b;
}

Output

function add(a, b) { return a + b; }

Arrow function spacing

Input

const double=x=>x*2

Output

const double = (x) => x * 2;

Object literal

Input

const user={name:'Ada',ok:true}

Output

const user = { name: "Ada", ok: true };

Nested call

Input

console.log(add(1,2))

Output

console.log(add(1, 2));

How to use

  1. Paste a JavaScript snippet into the input panel (Pretty print is the usual mode).
  2. If formatting fails, fix syntax errors in the source and try again.
  3. Copy the result. Switch to Minify only when you want a compact single-line-ish snippet.

What this tool is for

Readable JavaScript is easier to review in tickets and gists. This page reformats source text with consistent indentation and spacing. It is a formatter, not a bundler, not ESLint, and not an executor — your paste is never eval’d.

How it works

Pretty mode runs Prettier with the Babel parser (tab width from indent, default 2). Minify mode collapses whitespace with a simple pass — it is not a full terser-quality compress. Syntax errors surface as format failures instead of silently corrupting the file.

When to use it

Reading a minified function from DevTools, cleaning a gist, sharing a snippet in a ticket, and normalizing a short example before a PR comment.

When not to use it

Do not format a whole production webpack bundle in a tab and expect source maps. JSX/TS with types belongs on the TypeScript Formatter. JSON data belongs on the JSON Formatter. Do not treat formatted output as “more secure.”

How it compares to related tools

TypeScript Formatter understands type syntax. JSON Formatter is for data. HTML Formatter is for markup. Repo CI should still use Prettier as the source of truth.

Common mistakes

Formatting code that is actually JSON. Pasting proprietary code into a screenshot. Expecting minify mode to match terser. Assuming ESLint rules are applied.

Formatter, not a linter or runner

Prettier changes whitespace and a few syntactic preferences (quotes, semicolons) according to its defaults. It does not run your code, resolve modules, or apply ESLint semantic rules. Keep CI Prettier config as the authority for the repository.

Minify mode is best-effort

Minify on this page collapses whitespace; it is not a full minifier with mangling and dead-code elimination. Use it for compact demos, not as a production build step.

Frequently asked questions

Does this run my JavaScript?+

No. It reformats source text. It does not eval your paste.

Will it match Prettier in my repo?+

Close in spirit, not guaranteed identical. Use Prettier in CI with your shared config as the source of truth.

Is JSX supported?+

Simple JSX may format under the Babel parser; complex TSX is happier on the TypeScript Formatter.

Why did formatting fail?+

Syntax errors, incomplete snippets, or experimental syntax the parser rejects. Fix the source and retry.

Is my code uploaded?+

No. Formatting runs in this browser.

Does minify preserve behavior?+

Whitespace-only minify should not change JS meaning, but always run tests before shipping. Prefer your bundler for production.

Does this tool send my payload to CaseSwitch?+

No. Formatting, encoding, and naming conversions for this page run in your browser after load — your sample stays on the device.

Related guides

Read our original articles on this topic.

Related tools