Skip to content
UniKit

JavaScript formatter

Beautify or minify JavaScript and TypeScript with a hand-written lexer that understands nested ${} template literals, regex literals, // and /* */ comments and operators such as ?. ?? => ++ — statements are indented, operator spacing is normalized, and ASI-sensitive line breaks are never dropped.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Formatted output

Type some code above and the result shows up here.

What this tool does

  • Re-indent a minified or log-pasted JS / TS file so the control flow is readable before you touch it.
  • Apply one consistent style before a handover — block indentation, spaces around operators and after commas — without installing Prettier.
  • Strip comments and indentation from an inline `<script>` before shipping to shrink the HTML payload.
  • Catch syntax problems early: unclosed strings, templates, comments or regexes and unbalanced brackets are reported instead of silently reflowed.

Example

Input

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

Output

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

Only whitespace and indentation are rearranged: no token is added or removed, and string, template, regex and comment content stays byte for byte.

Frequently asked questions

Does formatting change what the code does?

No. It only adjusts whitespace, indentation and line breaks — no tokens are added or removed, statements are never reordered and no semicolons are inserted. Template literals, regex literals and comments are carried over as single blocks.

Why are object literals kept on one line?

Object and array literals, import / export lists and TypeScript interface bodies stay on a single line so that `import { a, b } from "x"` is not torn apart. Only statement blocks — function bodies, if, for, class bodies and so on — are expanded and indented.

Does minify remove line breaks, and can that break ASI?

It removes indentation and meaningless line breaks but keeps every break that can affect semantics: line breaks after `return`, `throw`, `break`, `continue` and `yield`, and continuation lines that start with `(`, `[`, `+`, `-` or `/` are preserved exactly, so minifying never changes the behaviour.

Are comments removed?

Minify drops comments by default, but license banners starting with `/*!` or `//!` are kept; enable “keep comments” to keep them all. Pretty mode always keeps comments.

Is TypeScript supported?

Yes. Type annotations, interfaces, generics, `?:`, `as` and `satisfies` are treated as ordinary tokens — no type checking and no compiler are involved.

Keywords:javascript formatterjs beautifyjs minifytypescript formatterprettifyjs 格式化js 美化js 压缩代码缩进模板字符串正则字面量ASI

Related tools