Skip to content

Commit 23c356f

Browse files
committed
Added exporting validateOrReject function.
1 parent 559c100 commit 23c356f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@ export function validate(schemaNameOrObject: Object|string,
4949
}
5050
}
5151

52+
/**
53+
* Validates given object and reject on error.
54+
*/
55+
export function validateOrReject(object: Object, validatorOptions?: ValidatorOptions): Promise<void>;
56+
57+
/**
58+
* Validates given object by a given validation schema and reject on error.
59+
*/
60+
export function validateOrReject(schemaName: string, object: Object, validatorOptions?: ValidatorOptions): Promise<void>;
61+
62+
/**
63+
* Validates given object by object's decorators or given validation schema and reject on error.
64+
*/
65+
export function validateOrReject(schemaNameOrObject: Object|string,
66+
objectOrValidationOptions?: Object|ValidatorOptions,
67+
maybeValidatorOptions?: ValidatorOptions): Promise<void> {
68+
if (typeof schemaNameOrObject === "string") {
69+
return getFromContainer(Validator).validateOrReject(schemaNameOrObject as string, objectOrValidationOptions as Object, maybeValidatorOptions);
70+
} else {
71+
return getFromContainer(Validator).validateOrReject(schemaNameOrObject as Object, objectOrValidationOptions as ValidatorOptions);
72+
}
73+
}
74+
5275
/**
5376
* Performs sync validation of the given object.
5477
* Note that this method completely ignores async validations.

0 commit comments

Comments
 (0)