Reading Third-Party JavaScript
By toolbelt maintainers ·
Updated
A bundled library is not meant to be read. Formatting gets it close enough that you can answer the one question you have.
What is this tool?
A JavaScript formatter re-prints code with consistent indentation and spacing. It does not undo minification — variable names stay short — but it makes the control flow followable.
How it works
Prettier parses the code into an AST and prints it back. Because it works from the AST, it understands where one statement ends and the next begins, which is why it does not break on semicolons inside strings or regexes.
Example
Before:
function f(a,b){if(!a)return null;const c=b.map(x=>x*2);return{a,c}}
After:
function f(a, b) {
if (!a) return null;
const c = b.map((x) => x * 2);
return { a, c };
}When to use it
When you need to know whether a library does something before you trust it. When a stack trace points into a vendor bundle. When you are trying to reproduce a bug in third-party code.
Optimization Tips
Do not try to read a formatted bundle top to bottom. Search for the string or the exported function you care about, then read only that function. A formatter helps you follow one function; it does not make 30,000 lines readable.
Frequently Asked Questions
Can it beautify minified code?
Why do I get a syntax error?
Does it run the code?
Can it fix actual bugs?
Related tools
- JSON FormatterBeautify, validate, minify, and view JSON. Format messy API responses into readable code or compress it to save bandwidth, running safely in your browser.
- JSON ValidatorValidate JSON syntax with detailed error messages. Catch trailing commas, missing brackets, and syntax errors instantly before sending payloads to your API.
- JSON MinifierCompress JSON to a single line. Remove all unnecessary whitespace and line breaks to reduce payload size for production APIs without altering the underlying data.
- JSON ViewerView JSON in an interactive, collapsible tree structure. Easily navigate massive API responses, expand specific nodes, and inspect deeply nested objects or arrays.