Why most formatters break on ordinary code
Most browser formatters count braces. They walk the text, add an indent level at every { and remove one at every }, and that holds until a brace turns up somewhere that is not code. One line like const open = "{"; is enough, and from there every remaining line in the file sits a level too deep.
Quotes cause the same damage in reverse. A comment reading // don't mutate props contains a single apostrophe. A formatter that tracks quotes without knowing it is inside a comment reads that apostrophe as the start of a string and stops seeing code until the next one, which might be 200 lines away.
Escapes and interpolation compound both. In "she said \"no\"" the middle pair are data, not delimiters. In a template literal, the ${ } interpolations hold real code and real braces while the text around them holds neither. Nothing short of a real parser gets every one of those right, which is why this uses one rather than a search and replace.
The slash that is not division
A forward slash opens a regular expression or performs division, and nothing about the character itself decides which. JavaScript resolves it from what came before: after a value it divides, after an operator, keyword or opening bracket it starts a pattern. Formatters that skip that check are guessing, and dense arithmetic is where they guess wrong.
Take two lines in sequence: const perUnit = total / qty; and const gstShare = tax / total;. Guess wrong on the first slash and everything between the two is swallowed as a regex body — semicolons, quotes and all — so the formatter loses track of where the statements end, and the indentation never recovers.
This tool makes the decision the engine makes, by remembering the last meaningful token before the slash. Division stays division. A pattern like /^\d{4}-\d{2}$/ stays a pattern, and the braces inside its quantifiers are not counted as blocks, which is precisely the case that pushes naive output four levels out.
What it changes, and what it leaves alone
Formatting here means the whitespace between tokens. Indentation is rebuilt from the block structure and spacing is made consistent, but anything inside a string, a regex or a comment is reproduced character for character, including its own spacing. Two spaces inside a message stay two spaces, because altering them would alter the program.
It is not a linter and not a minifier. It will not flag an unused variable, rename anything or shorten your code. It will not repair a missing brace either: a file with one { too many drifts steadily rightwards, which is usually the fastest way to find the line where the imbalance began.
The output is deterministic. The same input gives the same result every time, and formatting an already formatted file returns it unchanged, so it is safe to run over a snippet you are about to commit. Most people reach for it when reading someone else's code — a handler pasted into a ticket, or a script lifted from a page.