Last updated
Example: Minified Code → Beautified
// Before (minified):
function calculateTotal(items){return items.reduce((sum,item)=>sum+item.price*item.quantity,0);}const cart=[{price:10,quantity:2},{price:25,quantity:1}];console.log(calculateTotal(cart));
// After (beautified, 2-space indent):
function calculateTotal(items) {
return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
}
const cart = [
{ price: 10, quantity: 2 },
{ price: 25, quantity: 1 }
];
console.log(calculateTotal(cart));
Example: Inconsistently Formatted Code
// Before:
const user={name:'Alice',age:30,address:{city:'New York',zip:'10001'}}
function greet(user){
if(user.name){
console.log('Hello '+user.name)
}else{
console.log('Hello stranger')
}}
// After (beautified):
const user = {
name: 'Alice',
age: 30,
address: {
city: 'New York',
zip: '10001'
}
};
function greet(user) {
if (user.name) {
console.log('Hello ' + user.name);
} else {
console.log('Hello stranger');
}
}
Example: React JSX Component
// Before (minified JSX):
const Button=({label,onClick,disabled=false})=><button className={`btn ${disabled?'btn-disabled':'btn-primary'}`} onClick={onClick} disabled={disabled}>{label}</button>;
// After (beautified JSX):
const Button = ({ label, onClick, disabled = false }) => (
<button
className={`btn ${disabled ? 'btn-disabled' : 'btn-primary'}`}
onClick={onClick}
disabled={disabled}
>
{label}
</button>
);
Example: Class Syntax
// Before:
class EventEmitter{constructor(){this.events={}}on(event,listener){if(!this.events[event])this.events[event]=[];this.events[event].push(listener)}emit(event,...args){if(this.events[event])this.events[event].forEach(l=>l(...args))}}
// After:
class EventEmitter {
constructor() {
this.events = {};
}
on(event, listener) {
if (!this.events[event]) this.events[event] = [];
this.events[event].push(listener);
}
emit(event, ...args) {
if (this.events[event]) {
this.events[event].forEach(l => l(...args));
}
}
}
Example: Async/Await with Error Handling
// Before:
async function loadDashboard(){try{const[users,orders,stats]=await Promise.all([fetchUsers(),fetchOrders(),fetchStats()]);return{users,orders,stats}}catch(err){console.error('Dashboard load failed:',err);throw err}}
// After:
async function loadDashboard() {
try {
const [users, orders, stats] = await Promise.all([
fetchUsers(),
fetchOrders(),
fetchStats()
]);
return { users, orders, stats };
} catch (err) {
console.error('Dashboard load failed:', err);
throw err;
}
}
Formatting Options
- Indent style: 2 spaces (default), 4 spaces, or tabs
- Quote style: single quotes, double quotes, or preserve original
- Semicolons: always add, never add, or preserve original
- Trailing commas: none, ES5 (objects/arrays), or all (including function params)
- Print width: max line length before wrapping (default: 80)
- Bracket spacing: spaces inside object braces { key: value } vs {key: value}
Example: Quote Style Normalization
// Before (mixed quotes):
const config = {
host: "localhost",
port: '3000',
name: "my-app",
debug: 'true'
};
// After (normalized to single quotes):
const config = {
host: 'localhost',
port: '3000',
name: 'my-app',
debug: 'true'
};
Example: TypeScript Code
// Before:
interface User{id:number;name:string;email:string;role:'admin'|'user'}function getUserById(id:number):Promise<User|null>{return db.query<User>('SELECT * FROM users WHERE id = ?',[id]).then(rows=>rows[0]??null)}
// After:
interface User {
id: number;
name: string;
email: string;
role: 'admin' | 'user';
}
function getUserById(id: number): Promise<User | null> {
return db
.query<User>('SELECT * FROM users WHERE id = ?', [id])
.then(rows => rows[0] ?? null);
}
Paste any JavaScript, TypeScript, or JSX code into the beautifier, choose your formatting preferences, and get clean, consistently formatted output instantly.
Example: ES6+ Arrow Functions and Destructuring
// Before:
const fetchUser=async(id)=>{const{data,error}=await api.get(`/users/${id}`);if(error)throw new Error(error.message);return data;};
// After:
const fetchUser = async (id) => {
const { data, error } = await api.get(`/users/${id}`);
if (error) throw new Error(error.message);
return data;
};