forked from epfml/disco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_information.ts
100 lines (92 loc) · 2.29 KB
/
display_information.ts
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { Summary, isSummary } from './summary'
import { DataExample, isDataExample } from './data_example'
import { LabelType } from './label_type'
export function isDisplayInformation (raw: unknown): raw is DisplayInformation {
if (typeof raw !== 'object') {
return false
}
if (raw === null) {
return false
}
type Fields =
'dataExample' |
'dataExampleImage' |
'dataExampleText' |
'dataFormatInformation' |
'headers' |
'limitations' |
'model' |
'summary' |
'taskTitle' |
'tradeoffs'
const {
dataExample,
dataExampleImage,
dataExampleText,
dataFormatInformation,
headers,
limitations,
model,
summary,
taskTitle,
tradeoffs
} = raw as Record<Fields, unknown | undefined>
if (
typeof taskTitle !== 'string' ||
(dataExampleText !== undefined && typeof dataExampleText !== 'string') ||
(dataFormatInformation !== undefined && typeof dataFormatInformation !== 'string') ||
(tradeoffs !== undefined && typeof tradeoffs !== 'string') ||
(model !== undefined && typeof model !== 'string') ||
(dataExampleImage !== undefined && typeof dataExampleImage !== 'string') ||
(limitations !== undefined && typeof limitations !== 'string')
) {
return false
}
if (summary !== undefined && !isSummary(summary)) {
return false
}
if (
dataExample !== undefined && !(
Array.isArray(dataExample) &&
dataExample.every(isDataExample))
) {
return false
}
if (
headers !== undefined && !(
Array.isArray(headers) &&
headers.every((e) => typeof e === 'string'))
) {
return false
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _: DisplayInformation = {
taskTitle,
summary,
tradeoffs,
dataFormatInformation,
dataExampleText,
model,
dataExample,
headers,
dataExampleImage,
limitations
}
return true
}
export interface DisplayInformation {
taskTitle?: string
summary?: Summary
tradeoffs?: string
dataFormatInformation?: string
// TODO merge dataExample
dataExampleText?: string
model?: string
// TODO no need for undefined
dataExample?: DataExample[]
// TODO no need for undefined
headers?: string[]
dataExampleImage?: string
limitations?: string
labelDisplay?: LabelType
}