Prettify
Prettify (Code Formatting)
The process of reformatting code or data with consistent indentation, line breaks, and spacing to make it human-readable, effectively the reverse of minification.
技術的詳細
Prettifiers parse the input into an AST (or token stream for simpler formats), then print it back with configurable formatting rules. JSON.stringify(obj, null, 2) produces pretty-printed JSON with 2-space indentation. Dedicated formatters like Prettier (JS/CSS/HTML/JSON/YAML/Markdown) enforce opinionated style rules across entire codebases. XML/HTML beautifiers must preserve significant whitespace in
and blocks. The process is lossless for structured data but may alter insignificant whitespace in text content.
例
```javascript
// Prettify: web API example
const response = await fetch('/api/resource');
const data = await response.json();
console.log(data);
```