(
value: unknown,
path: string,
category: string
)
| 12 | |
| 13 | function isString(value: JsonValue): value is string { |
| 14 | return value !== null && value !== undefined && String(value) === value; |
| 15 | } |
| 16 | |
| 17 | function 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 | |
| 24 | export 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 = { |
no test coverage detected