UNPKG

@cowwoc/requirements

Version:

A fluent API for enforcing design contracts with automatic message generation.

36 lines 1.48 kB
import { isFalseFailed, isTrueFailed, AbstractValidator, ValidationTarget } from "../internal.mjs"; /** * Default implementation of `BooleanValidator`. */ class BooleanValidatorImpl extends AbstractValidator { /** * @param scope - the application configuration * @param configuration - the validator configuration * @param name - the name of the value * @param value - the value * @param context - the contextual information set by a parent validator or the user * @param failures - the list of validation failures * @throws TypeError if `name` is `undefined` or `null` * @throws RangeError if `name` contains whitespace, or is empty * @throws AssertionError if `scope`, `configuration`, `value`, `context` or `failures` are null */ constructor(scope, configuration, name, value, context, failures) { super(scope, configuration, name, value, context, failures); } isTrue() { if (this.value.validationFailed(v => v)) { this.failOnUndefinedOrNull(); this.addRangeError(isTrueFailed(this).toString()); } return this; } isFalse() { if (this.value.validationFailed(v => !v)) { this.failOnUndefinedOrNull(); this.addRangeError(isFalseFailed(this).toString()); } return this; } } export { BooleanValidatorImpl }; //# sourceMappingURL=BooleanValidatorImpl.mjs.map