MCPcopy Create free account
hub / github.com/amrkmn/x / parseExtensionConfig

Function parseExtensionConfig

scripts/validation.ts:14–36  ·  view source on GitHub ↗
(
    value: unknown,
    path: string,
    category: string
)

Source from the content-addressed store, hash-verified

12
13function isString(value: JsonValue): value is string {
14 return value !== null && value !== undefined && String(value) === value;
15}
16
17function asString(value: JsonValue, path: string): string {
18 if (!isString(value) || value.length === 0) {
19 throw new Error(`Invalid ${path}: expected non-empty string`);
20 }
21 return value;
22}
23
24export function parseExtensionConfig(
25 value: JsonValue,
26 path: string,
27 category: string
28): ExtensionConfig {
29 if (category !== 'mihon' && category !== 'aniyomi') {
30 throw new Error(`Invalid category ${category}: expected "mihon" or "aniyomi"`);
31 }
32 if (!isRecord(value)) throw new Error(`Invalid ${path}: expected object`);
33
34 const commit = value.commit;
35 if (commit !== undefined && !isString(commit)) {
36 throw new Error(`Invalid ${path}.commit: expected string`);
37 }
38
39 const result: ExtensionConfig = {

Callers 1

parseExtensionsDataFunction · 0.85

Calls 2

isRecordFunction · 0.70
asStringFunction · 0.70

Tested by

no test coverage detected