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.

22 lines (19 loc) 952 B
import { BaseType, WithBGuardType, MapMixTypes } from '../../commonTypes.js'; import { CommonSchema } from '../../core.js'; import '../../InferType.js'; import '../../helpers/constants.js'; /** * @description Creates a new schema for validating values that can match any one of the specified primitive types. * @template T * @param {T} valueTypes - An array of primitive types that the value can match. * @returns {WithBGuardType<CommonSchema, MapMixTypes<T>>} A new schema for validating values that can match any of the specified types. * @example * const schema = oneOfTypes(['string', 'number']); * parseOrFail(schema, 'hello'); // Validates successfully * parseOrFail(schema, 42); // Validates successfully * parseOrFail(schema, true); // Throws a validation error * * @instance Of CommonSchema */ declare function oneOfTypes<T extends BaseType[]>(valueTypes: T): WithBGuardType<CommonSchema, MapMixTypes<T>>; export { oneOfTypes };