File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ *
3
+ * @param obj object that needs to be validated
4
+ * @param schema template for validation
5
+ * @returns whether missed some keys
6
+ */
1
7
export function isValid ( obj : Object , schema : Object ) {
2
8
for ( let key in schema ) {
3
9
if ( ! obj . hasOwnProperty ( key ) ) {
4
10
return false
5
11
}
6
- if ( typeof schema [ key ] === 'object' && schema [ key ] !== null ) {
7
- if ( ! isValid ( obj [ key ] , schema [ key ] ) ) {
8
- return false
9
- } else if ( typeof obj [ key ] !== schema [ key ] ) {
10
- return false
12
+ if ( schema [ key ] !== null ) {
13
+ if ( typeof schema [ key ] === 'string' ) {
14
+ if ( typeof obj [ key ] !== schema [ key ] ) {
15
+ return false
16
+ }
17
+ } else if ( typeof schema [ key ] === 'object' ) {
18
+ if ( ! isValid ( obj [ key ] , schema [ key ] ) ) {
19
+ return false
20
+ }
11
21
}
12
22
}
13
23
}
You can’t perform that action at this time.
0 commit comments