UNPKG

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.09 kB
import { RequiredValidation } from '../../core.mjs'; import '../../commonTypes.mjs'; import '../../InferType.mjs'; import '../../helpers/constants.mjs'; /** * @description Creates a custom assertion that checks if a value is equal to the expected value. * @notice It has already been implemented in the number, bigint and string schema. There is no need to use it as a custom assert. * @param {unknown} expected The value that the received value is expected to match. * @returns {RequiredValidation} A validation function that takes a received value and an exception context. * @throws {ValidationError} If the received value does not match the expected value. * @example * const schema = number().custom(equalTo(5)); // Define a schema with a custom assertion * parseOrFail(schema, 5); // Valid * parseOrFail(schema, 3); // Throws an error: 'The received value is not equal to expected' * * @translation Error Translation Key = 'm:equalTo' */ declare const equalTo: { (expected: unknown): RequiredValidation; key: string; message: string; }; export { equalTo };