-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidate.jd
19 lines (16 loc) · 848 Bytes
/
Validate.jd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function validateObject(obj, requiredKeys, checkForNullUndefined = true) {
const validationErrors = requiredKeys
.map(key => (!obj.hasOwnProperty(key) ? `Field: ${key} is missing` : null)) // Check for missing fields
.concat(
checkForNullUndefined
? Object.keys(obj)
.map(key => (obj[key] === null || obj[key] === undefined ? `Field: ${key} has an invalid value (null or undefined)` : null))
: []
) // Optional check for null/undefined (conditional with map)
.reduce((errors, error) => error ? errors.concat(error) : errors, []); // Concatenate only non-null error messages
if (validationErrors.length > 0) {
console.error("User understanding statement validation errors:\n", validationErrors.join("\n"));
}
return validationErrors.length === 0;
}
// Example usage (same as before)