export function extractHiddenField(html: string, name: string): string {
const re = new RegExp(`id="${name}"[^>]*value="([^"]*)"`, "i");
const match = html.match(re);
if (match) return match[1];
const re2 = new RegExp(`name="${name}"[^>]*value="([^"]*)"`, "i");
const match2 = html.match(re2);
return match2?.[1] ?? "";
}
export function stripTags(html: string): string {
return html.replace(/<[^>]*>/g, "").trim();
}
export function decodeHtmlEntities(text: string): string {
return text
.replace(/ /g, " ")
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, "\"")
.replace(/(\d+);/g, (_, n) => String.fromCharCode(Number(n)));
}
export function padCell(val: string, w: number): string {
const displayWidth = [...val].reduce(
(sum, ch) => sum + (ch.charCodeAt(0) > 0x7f ? 2 : 1),
0
);
return val + " ".repeat(Math.max(0, w - displayWidth));
}