forked from henninghall/react-native-date-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpropChecker.js
More file actions
43 lines (38 loc) · 1.1 KB
/
propChecker.js
File metadata and controls
43 lines (38 loc) · 1.1 KB
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
export function throwIfInvalidProps(props) {
checks.forEach(check => check.validate(props))
}
class PropCheck {
constructor(isInvalid, errorText) {
this.isInvalid = isInvalid
this.errorText = errorText
}
validate = props => {
if (this.isInvalid(props)) {
throw new Error(
`${this.errorText} Check usage of react-native-date-picker.`
)
}
}
}
const widthCheck = new PropCheck(
props =>
props &&
props.style &&
props.style.width &&
typeof props.style.width !== 'number',
'Invalid style: width. Width needs to be a number. Percentages or other values are not supported.'
)
const heightCheck = new PropCheck(
props =>
props &&
props.style &&
props.style.height &&
typeof props.style.height !== 'number',
'Invalid style: height. Height needs to be a number. Percentages or other values are not supported.'
)
const modeCheck = new PropCheck(
props =>
props && props.mode && !['datetime', 'date', 'time'].includes(props.mode),
"Invalid mode. Valid modes: 'datetime', 'date', 'time'"
)
const checks = [widthCheck, heightCheck, modeCheck]