Validator Utility
The validator utility helps you validate objects against a set of required fields.
API Reference
validator(
obj,requiredFields):ValidationResult
Validates an object by checking if it contains all the required fields.
Parameters
| Parameter | Type | Description |
|---|---|---|
obj | null | Record<string, any> | The object to be validated. |
requiredFields | string | Record<string, string> | The list of required fields. If it's a string, it should contain keys separated by spaces. If it's an object, it should contain key-value pairs where the key is the field name and the value is a boolean indicating whether the field is required or not. |
Returns
Returns a ValidationResult object with validation status and missing fields.
Throws
Throws an error if the requiredFields parameter is not a string or an object.