Skip to content

Commit c340af2

Browse files
committed
bugfix for key-checking
1 parent 4e5284a commit c340af2

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Diff for: __test__/utils.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
/**
2+
*
3+
* @param obj object that needs to be validated
4+
* @param schema template for validation
5+
* @returns whether missed some keys
6+
*/
17
export function isValid(obj: Object, schema: Object) {
28
for (let key in schema) {
39
if (!obj.hasOwnProperty(key)) {
410
return false
511
}
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+
}
1121
}
1222
}
1323
}

0 commit comments

Comments
 (0)