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.

46 lines (43 loc) 1.89 kB
import { WithBGuardType } from '../../commonTypes.js'; import { CommonSchema } from '../../core.js'; import '../../InferType.js'; import '../../helpers/constants.js'; /** * @description Creates a new schema for validating string values. * @returns {WithBGuardType<StringSchema, string>} A new instance of `StringSchema` for validating strings. * @example * const schema = string(); * parseOrFail(schema, 'hello'); // Validates successfully * parseOrFail(schema, 123); // Throws a validation error * * @instance Of StringSchema */ declare function string(): WithBGuardType<StringSchema, string>; declare class StringSchema extends CommonSchema { protected _string: number; private limit; /** * @method equalTo * @description Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type. * @param expectedValue - The value that the schema must exactly match. * @returns The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type * @example * string().equalTo('hello'); // Infers the type 'hello' * * @public */ equalTo<Y extends string>(expectedValue: Y): WithBGuardType<this, Y>; /** * @method oneOfValues * @description Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type. * @param expectedValues - An array of values that the schema can match. * @returns The schema instance restricted to one of the specified values, with the union of those values inferred as the TypeScript type. * @example * string().oneOfValues(['foo', 'bar']); // Infers the type 'foo' | 'bar' * * @public */ oneOfValues<Y extends string>(expectedValue: Y[]): WithBGuardType<this, Y>; private limitCheck; } export { string };