bguard
Version:
**bguard** is a powerful, flexible, and type-safe validation library for TypeScript. It allows developers to define validation schemas for their data structures and ensures that data conforms to the expected types and constraints.
26 lines (23 loc) • 1.02 kB
text/typescript
import { RequiredValidation } from '../../core.mjs';
import '../../commonTypes.mjs';
import '../../InferType.mjs';
import '../../helpers/constants.mjs';
/**
* @description Asserts that a date value is not greater than a specified maximum value.
* @param {Date | string} expected The maximum allowable value.
* @returns {RequiredValidation} A validation function that takes a received Date or string and an exception context.
* @throws {ValidationError} if the received value is greater than the expected maximum value.
* @example
* const schema = date().custom(dateMax('2024-12-31'));
* parseOrFail(schema, new Date('2024-12-30')); // Valid
* parseOrFail(schema, new Date('2024-12-31')); // Valid
* parseOrFail(schema, new Date('2025-01-01')); // Throws an error: 'The received value is greater than expected'
*
* @translation Error Translation Key = 'dt:max'
*/
declare const dateMax: {
(expected: Date | string): RequiredValidation;
key: string;
message: string;
};
export { dateMax };