【前端】JS实现SQL格式化
sqlFormatter
sql-formatter - npm (npmjs.com)
const sqlFormatter = require('@/utils/sqlFormatter')
let sql = `select count(1) as cnt from t_user where id < 7`;
// 格式化
// let sqlF = sqlFormatter.format(sql);
let sqlF = sqlFormatter.format(sql, {
language:'mysql',
});
/**
* indent: " ",
* uppercase:false,
* linesBetweenQueries: 2
*/
console.log(sqlF)
增加样式
<style>
/* 设置 white-space 样式 */
pre {
white-space: pre-wrap;
}
</style>