-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
70 lines (63 loc) · 1.58 KB
/
example.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const buster = require("./src/object-buster");
const obj = {
name: "Barney Stinson",
age: 36,
address: {
city: "New York",
zip: "10001",
},
hobbies: ["womanizing", "suiting up", "playing laser tag"],
education: {
degree: "",
major: "Business",
year: 2003,
},
work: {
company: "Goliath National Bank",
position: "Corporate Executive",
projects: ["Project C", "Project D"],
},
preferences: {
notifications: {
ios: true,
android: undefined,
},
theme: "suits",
},
};
try {
// Validate the object strictly (undefined, null, empty)
buster.strict(obj);
} catch (error) {
console.error("Strict validation error:", error.message);
}
try {
// Validate the object for undefined or null properties
buster.must(obj);
} catch (error) {
console.error("Must validation error:", error.message);
}
try {
// Check for undefined properties recursively
buster.checkUndefined(obj);
} catch (error) {
console.error("Check undefined error:", error.message);
}
try {
// Check for null properties recursively
buster.checkNull(obj);
} catch (error) {
console.error("Check null error:", error.message);
}
try {
// Check for empty properties recursively
buster.checkEmpty(obj);
} catch (error) {
console.error("Check empty error:", error.message);
}
/**
* Strict validation error: Property 'degree' cannot be an empty string.
* Must validation error: Property 'android' cannot be undefined.
* Check undefined error: Property 'android' cannot be undefined.
* Check empty error: Property 'degree' cannot be an empty string.
*/