通用代码格式化

重新缩进和排版源代码以便阅读;不能代替运行验证或业务规则检查。

输入: 文本结果: 文本

文本输入

案例

Read a price calculation in integer cents

输入

function total(cents,qty){return cents*qty;}

Expected answer

function total(cents, qty) {
    return cents * qty;
}
Inspect a retry decision for HTTP 429

输入

if(status===429){retryAfter(30);}

Expected answer

if (status === 429) {
    retryAfter(30);
}
Keep an escaped newline inside a JavaScript string

输入

var forecast="Rain\nSun";show(forecast);

Expected answer

var forecast = "Rain\nSun";
show(forecast);
Keep URL punctuation inside a quoted string

输入

var url="https://example.org/search?q=caf%C3%A9&limit=5";open(url);

Expected answer

var url = "https://example.org/search?q=caf%C3%A9&limit=5";
open(url);
Inspect a JSON round-trip without executing it

输入

function copy(value){return JSON.parse(JSON.stringify(value));}

Expected answer

function copy(value) {
    return JSON.parse(JSON.stringify(value));
}

相关工具

代码整理

操作参考

查看原始技术文档 (English)