-
-
Notifications
You must be signed in to change notification settings - Fork 400
/
Copy pathconfiguration.ts
39 lines (32 loc) · 912 Bytes
/
configuration.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
import { Configuration } from './types'
export function isConfiguration(value: unknown): value is Configuration {
// Config must be an object
if (typeof value !== 'object') {
return false
}
// Config must not be null
if (value === null) {
return false
}
// This helps to get better support for TypeScript
const config = value as Record<string, unknown>
// If extends is defined, it must be an array
if (config.extends !== undefined) {
if (!Array.isArray(config.extends)) {
return false
}
// Any value within extens must be a string
for (const extension of config.extends) {
if (typeof extension !== 'string') {
return false
}
}
}
// If extends is defined, it must be an object
if (config.rules !== undefined) {
if (typeof config.rules !== 'object' && config.rules !== null) {
return false
}
}
return true
}