tyneq / ValidationBuilder
Class: ValidationBuilder
Defined in: src/utility/ValidationBuilder.ts:19
Accumulates validation errors and throws a single ValidationError containing all of them.
Use when multiple independent arguments must be validated together so callers see all failures in one throw rather than one at a time.
Example
ts
new ValidationBuilder()
.check(() => ArgumentUtility.checkNotOptional({ selector }))
.check(() => ArgumentUtility.checkPositive({ count }))
.throwIfAny();Constructors
Constructor
new ValidationBuilder():
ValidationBuilder
Returns
ValidationBuilder
Methods
check()
check(
fn):this
Defined in: src/utility/ValidationBuilder.ts:25
Runs fn and collects any thrown error message. Returns this for chaining.
Parameters
| Parameter | Type |
|---|---|
fn | () => void |
Returns
this
throwIfAny()
throwIfAny():
void
Defined in: src/utility/ValidationBuilder.ts:39
Throws a ValidationError with all collected messages if any check calls failed. Does nothing when no errors were collected.
Returns
void