It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers




JSR Score
29%
Published
5 months ago (0.1.2)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798// deno-lint-ignore-file no-explicit-any import { StringSchema } from "./schemas/string.ts"; import { NumberSchema } from "./schemas/number.ts"; import { LiteralSchema } from "./schemas/literal.ts"; import type { Schema as ISchema } from "./base.ts"; import { BigintSchema } from "./schemas/bigint.ts"; import { BooleanSchema } from "./schemas/boolean.ts"; import { DateSchema } from "./schemas/date.ts"; import { SymbolSchema } from "./schemas/symbol.ts"; import { UndefinedSchema } from "./schemas/undefined.ts"; import { NullSchema } from "./schemas/null.ts"; import { VoidSchema } from "./schemas/void.ts"; import { AnySchema } from "./schemas/any.ts"; import { UnknownSchema } from "./schemas/unknown.ts"; import { NeverSchema } from "./schemas/never.ts"; import { ObjectSchema } from "./schemas/object.ts"; import { UnionSchema } from "./schemas/union.ts"; import { OptionalSchema } from "./schemas/optional.ts"; import { NullableSchema } from "./schemas/nullable.ts"; import { NullishSchema } from "./schemas/nullish.ts"; import { ResultSchema } from "./schemas/result.ts"; import { OptionSchema } from "./schemas/option.ts"; import { EnumSchema } from "./schemas/enum.ts"; import { ArraySchema } from "./schemas/array.ts"; // deno-lint-ignore no-namespace export namespace vd { export type Schema<T> = ISchema<T>; export const string = (msg?: string): StringSchema => new StringSchema(msg); export const literal = <L extends string>( lit: L, msg?: string, ): LiteralSchema<L> => new LiteralSchema<L>(lit, msg); export const number = (msg?: string): NumberSchema => new NumberSchema(msg); export const bigint = (msg?: string): BigintSchema => new BigintSchema(msg); export const boolean = (msg?: string): BooleanSchema => new BooleanSchema(msg); export const date = (msg?: string): DateSchema => new DateSchema(msg); export const symbol = (msg?: string): SymbolSchema => new SymbolSchema(msg); export const undefined_ = (msg?: string): UndefinedSchema => new UndefinedSchema(msg); export const null_ = (msg?: string): NullSchema => new NullSchema(msg); export const void_ = (msg?: string): VoidSchema => new VoidSchema(msg); export const any = (msg?: string): AnySchema => new AnySchema(msg); export const unknown = (msg?: string): UnknownSchema => new UnknownSchema(msg); export const never = (msg?: string): NeverSchema => new NeverSchema(msg); export const obj = <S extends Record<string, Schema<any>>>( schema: S, msg?: string | { mismatch?: string; nullObject?: string; unexpectedProperty?: string; propertyValidation?: string; missingProperty?: string; }, ): ObjectSchema<S> => new ObjectSchema<S>(schema, msg); export const union = <U extends Schema<any>[]>( schemas: U, msg?: string | { mismatch?: string; unionValidation?: string; }, ): UnionSchema<U> => new UnionSchema<U>(schemas, msg); export const array = <S extends Schema<any>>( schema: S, msg?: string | { mismatch?: string; element?: string }, ): ArraySchema<S> => new ArraySchema<S>(schema, msg); export const optional = <S extends Schema<any>>( schema: S, msg?: string, ): OptionalSchema<S> => new OptionalSchema<S>(schema, msg); export const nullable = <S extends Schema<any>>( schema: S, msg?: string, ): NullableSchema<S> => new NullableSchema<S>(schema, msg); export const nullish = <S extends Schema<any>>( schema: S, msg?: string, ): NullishSchema<S> => new NullishSchema<S>(schema, msg); export const result = <T extends Schema<any>, E extends Schema<any>>( okSchema: T, errSchema: E, ): ResultSchema<T, E> => new ResultSchema<T, E>(okSchema, errSchema); export const option = <T extends Schema<any>>( schema: T, ): OptionSchema<T> => new OptionSchema<T>(schema); export const enum_ = <E extends (number | string)[]>( e: E, msg?: string, ): EnumSchema<E> => new EnumSchema(e, msg); export type infer<S extends Schema<unknown>> = S extends Schema<infer T> ? T : never; } export default vd;