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.

1 lines 1.21 kB
{"version":3,"sources":["../src/asserts/mix/index.ts"],"sourcesContent":["import { BaseType, MapMixTypes, WithBGuardType } from '../../commonTypes';\nimport { CommonSchema } from '../../core';\n\n/**\n * @description Creates a new schema for validating values that can match any one of the specified primitive types.\n * @template T\n * @param {T} valueTypes - An array of primitive types that the value can match.\n * @returns {WithBGuardType<CommonSchema, MapMixTypes<T>>} A new schema for validating values that can match any of the specified types.\n * @example\n * const schema = oneOfTypes(['string', 'number']);\n * parseOrFail(schema, 'hello'); // Validates successfully\n * parseOrFail(schema, 42); // Validates successfully\n * parseOrFail(schema, true); // Throws a validation error\n *\n * @instance Of CommonSchema\n */\nexport function oneOfTypes<T extends BaseType[]>(valueTypes: T): WithBGuardType<CommonSchema, MapMixTypes<T>> {\n return new CommonSchema({ type: valueTypes, requiredValidations: [] }) as WithBGuardType<\n CommonSchema,\n MapMixTypes<T>\n >;\n}\n"],"mappings":";;;;;AAgBO,SAAS,WAAiC,YAA6D;AAC5G,SAAO,IAAI,aAAa,EAAE,MAAM,YAAY,qBAAqB,CAAC,EAAE,CAAC;AAIvE;","names":[]}