2024.js/debug/idv.ts

60 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-07-07 21:00:20 -04:00
import { h } from "../lib/html";
import { Idv, StringFromDocument } from "../lib/idv";
export function IdvDebug() {
const textarea = h(
"textarea",
{
cols: 80,
rows: 40,
oninput(ev) {
parse();
},
},
`# Idv Testing Ground
2024-07-10 00:31:33 -04:00
User: tangent128
Uid: 10000
Shell: tclsh
Group: users
Group: sudo
Banner:
+------------------+
|Welcome to Debian!|
+------------------+
User: tirga
Uid: 10101
Shell: bash
Group: users
`
2024-07-07 21:00:20 -04:00
);
const pre = h("pre");
function parse() {
try {
const idv = Idv.parse(textarea.value);
pre.textContent = JSON.stringify(
2024-07-10 00:31:33 -04:00
idv.getMap("User", UserFromDocument),
2024-07-07 21:00:20 -04:00
null,
2
);
} catch (e) {
pre.textContent = String(e);
}
}
parse();
return [textarea, pre];
}
2024-07-10 00:31:33 -04:00
const UserFromDocument = (lines: string[]) => {
const idv = Idv.parseLines(lines);
return {
shell: idv.getProperty("Shell", String, StringFromDocument),
groups: idv.getList("Group", String, StringFromDocument),
banner: idv.getProperty("Banner", String, StringFromDocument),
};
};