impl map helper
This commit is contained in:
parent
2f9bb73107
commit
525c6fa954
2 changed files with 37 additions and 13 deletions
24
debug/idv.ts
24
debug/idv.ts
|
@ -12,7 +12,8 @@ export function IdvDebug() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
`# Idv Testing Ground
|
`# Idv Testing Ground
|
||||||
Uid: 0
|
User: tangent128
|
||||||
|
Uid: 10000
|
||||||
Shell: tclsh
|
Shell: tclsh
|
||||||
Group: users
|
Group: users
|
||||||
Group: sudo
|
Group: sudo
|
||||||
|
@ -20,7 +21,12 @@ Banner:
|
||||||
+------------------+
|
+------------------+
|
||||||
|Welcome to Debian!|
|
|Welcome to Debian!|
|
||||||
+------------------+
|
+------------------+
|
||||||
#`
|
|
||||||
|
User: tirga
|
||||||
|
Uid: 10101
|
||||||
|
Shell: bash
|
||||||
|
Group: users
|
||||||
|
`
|
||||||
);
|
);
|
||||||
|
|
||||||
const pre = h("pre");
|
const pre = h("pre");
|
||||||
|
@ -30,10 +36,7 @@ Banner:
|
||||||
const idv = Idv.parse(textarea.value);
|
const idv = Idv.parse(textarea.value);
|
||||||
|
|
||||||
pre.textContent = JSON.stringify(
|
pre.textContent = JSON.stringify(
|
||||||
{
|
idv.getMap("User", UserFromDocument),
|
||||||
shell: idv.getProperty("Shell", String, StringFromDocument),
|
|
||||||
groups: idv.getList("Group", String, StringFromDocument),
|
|
||||||
},
|
|
||||||
null,
|
null,
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
|
@ -45,3 +48,12 @@ Banner:
|
||||||
|
|
||||||
return [textarea, pre];
|
return [textarea, pre];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
12
lib/idv.ts
12
lib/idv.ts
|
@ -85,6 +85,18 @@ export class Idv {
|
||||||
: parseDistinguisher(distinguisher)
|
: parseDistinguisher(distinguisher)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getMap<T>(
|
||||||
|
name: string,
|
||||||
|
parseDocument: DocumentParser<T>
|
||||||
|
): Record<string, T> {
|
||||||
|
return Object.fromEntries(
|
||||||
|
(this.collections[name] ?? []).map(([distinguisher, document]) => [
|
||||||
|
distinguisher,
|
||||||
|
parseDocument(document),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const StringFromDocument = (lines: string[]) => lines.join("\n");
|
export const StringFromDocument = (lines: string[]) => lines.join("\n");
|
||||||
|
|
Loading…
Add table
Reference in a new issue