djskage
Version:
A Discord.js extension for utility commands
26 lines (25 loc) • 845 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const buffer_1 = require("buffer");
class Pretty {
static html(html) {
html = html.replace(/>\s+</g, '><').trim();
let formatted = '';
const lines = html.split(/(?=<)/g);
let indentLevel = 0;
for (let line of lines) {
if (line.match(/^<\/\w/))
indentLevel--;
formatted += ' '.repeat(Math.max(indentLevel, 0)) + line.trim() + '\n';
if (line.match(/^<[^\/!][^>]*[^\/]>$/))
indentLevel++;
}
formatted = formatted.trim();
return buffer_1.Buffer.from(formatted);
}
static json(json) {
let pretty = JSON.stringify(JSON.parse(json), null, 2);
return buffer_1.Buffer.from(pretty);
}
}
exports.default = Pretty;