-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmodule.ts
More file actions
30 lines (27 loc) · 763 Bytes
/
module.ts
File metadata and controls
30 lines (27 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Handler } from "./handlers/mod.ts";
import { FormattedString } from "./deps.ts";
export interface Module {
name: string;
handlers: Handler[];
help?: string | FormattedString;
}
export function isModule(value: unknown): value is Module {
const obj = Object(value);
return (
typeof obj.name === "string" &&
/^[a-z]{1,10}$/.test(obj.name) &&
Array.isArray(obj.handlers) &&
obj.handlers.filter((handler: unknown) => handler instanceof Handler)
.length != 0
);
}
export function getHelp(mod: Module) {
if (typeof mod.help !== "undefined") {
const length = typeof mod.help === "string"
? mod.help.length
: mod.help.text.length;
if (length > 0 && length <= 4096) {
return mod.help;
}
}
}