We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4e5284a commit c340af2Copy full SHA for c340af2
__test__/utils.ts
@@ -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
+ */
7
export function isValid(obj: Object, schema: Object) {
8
for (let key in schema) {
9
if (!obj.hasOwnProperty(key)) {
10
return false
11
}
- if (typeof schema[key] === 'object' && schema[key] !== null) {
- if (!isValid(obj[key], schema[key])) {
- return false
- } else if (typeof obj[key] !== schema[key]) {
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
20
21
22
23
0 commit comments