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.

29 lines (26 loc) 1.38 kB
import { RequiredValidation } from '../../core.js'; import '../../commonTypes.js'; import '../../InferType.js'; import '../../helpers/constants.js'; /** * @description Asserts that a string value contains at least one special character. * @param {string} [allowedSpecialChars=*] The string containing allowed special characters. Defaults to '*@$!#%&()^~{}'. * @returns {RequiredValidation} A validation function that takes a received string and an exception context. * @throws {ValidationError} if the received value does not contain at least one of the allowed special characters. * @example * const schema = string().custom(atLeastOneSpecialChar()); // Default special characters * parseOrFail(schema, 'abc!def'); // Valid * parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one special character' * * const customSchema = string().custom(atLeastOneSpecialChar('@$')); // Custom special characters * parseOrFail(customSchema, 'abc@def'); // Valid * parseOrFail(customSchema, 'abcdef'); // Throws an error: 'The received value does not contain at least one special character' * * @translation Error Translation Key = 's:atLeastOneSpecialChar' */ declare const atLeastOneSpecialChar: { (allowedSpecialChars?: string): RequiredValidation; key: string; message: string; }; export { atLeastOneSpecialChar };