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.

27 lines (24 loc) 1.17 kB
import { RequiredValidation } from '../../core.js'; import '../../commonTypes.js'; import '../../InferType.js'; import '../../helpers/constants.js'; /** * @description Asserts that the string value is a valid URL with optional protocol validation. * @param {string} [protocol] The protocol that the URL must start with (e.g., 'http'). If not provided, any URL starting with 'http://' or 'https://' is considered valid. * @returns {RequiredValidation} A validation function that takes a received string and an exception context. * @throws {ValidationError} if the received value does not match the expected URL pattern. * @example * const schema = string().custom(validUrl()); // Validates any URL starting with 'http://' or 'https://' * parseOrFail(schema, 'http://example.com'); // Valid * parseOrFail(schema, 'https://example.com'); // Valid * parseOrFail(schema, 'ftp://example.com'); // Throws an error * parseOrFail(schema, 'http:example.com'); // Throws an error * * @translation Error Translation Key = 's:url' */ declare const validUrl: { (protocol?: string): RequiredValidation; key: string; message: string; }; export { validUrl };