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.
34 lines (31 loc) • 1.11 kB
TypeScript
import { RequiredValidation } from '../../core.js';
import '../../commonTypes.js';
import '../../InferType.js';
import '../../helpers/constants.js';
/**
* @description Ensures that the object has no more than the specified number of keys.
* @param {number} expected - The maximum number of keys allowed in the object.
* @returns {RequiredValidation} A validation function that takes a received object and an exception context.
* @throws {ValidationError} if the number of the received keys is greater than the expected value.
* @example
* const schema = object({
* name: string(),
* email: string(),
* })
* .allowUnrecognized()
* .custom(maxKeys(2));
*
* // This will pass
* parseOrFail(schema, { name: 'John', email: 'john@example.com' });
*
* // This will throw an error because there are 3 keys
* parseOrFail(schema, { name: 'John', email: 'john@example.com', address: '123 Main St' });
*
* @translation Error Translation Key = 'o:maxKeys'
*/
declare const maxKeys: {
(expected: number): RequiredValidation;
key: string;
message: string;
};
export { maxKeys };