UNPKG

@cowwoc/requirements

Version:

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

59 lines (58 loc) 2.9 kB
import { type Configuration, type NumberValidator, type ValidationFailure, type ApplicationScope, AbstractValidator, ValidationTarget } from "../internal.mjs"; /** * Default implementation of `NumberValidator`. */ declare class NumberValidatorImpl<T extends number | undefined | null> extends AbstractValidator<T> implements NumberValidator<T> { /** * @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: ApplicationScope, configuration: Configuration, name: string, value: ValidationTarget<T>, context: Map<string, unknown>, failures: ValidationFailure[]); isNegative(): this; isNotNegative(): this; isZero(): this; isNotZero(): this; isPositive(): this; isNotPositive(): this; isGreaterThan(value: number): this; isGreaterThanOrEqualTo(minimumInclusive: number, name?: string): this; isLessThan(maximumExclusive: number, name?: string): this; isLessThanOrEqualTo(maximumInclusive: number, name?: string): this; isBetween(minimumInclusive: number, maximumExclusive: number): this; isBetween(minimum: number, minimumIsInclusive: boolean, maximum: number, maximumIsInclusive: boolean): this; /** * Normalize the parameters of isBetween(). * * @param minimum - the lower bound of the range * @param maximumExclusiveOrMinimumIsInclusive - the upper bound of the range, or `true` if the lower bound * of the range is inclusive * @param maximum - the upper bound of the range * @param maximumIsInclusive - `true` if the upper bound of the range is inclusive */ static normalizeIsBetweenParameters(minimum: number, maximumExclusiveOrMinimumIsInclusive: number | boolean, maximum?: number, maximumIsInclusive?: boolean): { minimum: number; minimumIsInclusive: boolean; maximum: number; maximumIsInclusive: boolean; }; isFinite(): this; isInfinite(): this; isMultipleOf(factor: number): this; /** * @param value - the value * @param factor - the number that the value is being divided by * @returns true if the value is a multiple of `factor` */ static valueIsMultipleOf(value: number, factor: number): boolean; isNotMultipleOf(factor: number): this; isNumber(): this; isNotNumber(): this; } export { NumberValidatorImpl };