yup
- Version 1.5.0
- Published
- 259 kB
- 4 dependencies
- MIT license
Install
npm i yup
yarn add yup
pnpm add yup
Overview
Dead simple Object schema validation
Index
Variables
Functions
Classes
Schema
- asNestedTest()
- cast()
- clone()
- concat()
- default()
- defined()
- deps
- describe()
- exclusiveTests
- getDefault()
- isType()
- isValid()
- isValidSync()
- label()
- meta()
- nonNullable()
- notOneOf()
- notRequired()
- nullability()
- nullable()
- oneOf()
- optional()
- optionality()
- required()
- resolve()
- resolveOptions()
- runTests()
- spec
- strict()
- strip()
- test()
- tests
- transform()
- transforms
- type
- typeError()
- validate()
- validateSync()
- when()
- withMutation()
Interfaces
Type Aliases
- AnyMessageParams
- AnyObject
- AnyObjectSchema
- AnySchema
- Asserts
- CastOptions
- CreateErrorOptions
- DefaultFromShape
- DefaultThunk
- Defined
- Flags
- InferType
- MakePartial
- Maybe
- Message
- MixedTypeGuard
- NotNull
- ObjectShape
- Optionals
- SchemaFieldDescription
- SchemaMetadata
- SetFlag
- TestConfig
- TestContext
- TestFunction
- TestOptions
- ToggleDefault
- TypeFromShape
- UnsetFlag
Namespaces
Variables
variable defaultLocale
const defaultLocale: LocaleObject;
Functions
function addMethod
addMethod: { <T extends ISchema<any, any, any, any>>( schemaType: (...arg: any[]) => T, name: string, fn: (this: T, ...args: any[]) => T ): void; <T extends abstract new (...args: any) => ISchema<any, any, any, any>>( schemaType: T, name: string, fn: (this: InstanceType<T>, ...args: any[]) => InstanceType<T> ): void;};
function array
array: typeof create$2;
function bool
bool: typeof create$7;
function boolean
boolean: typeof create$7;
function date
date: typeof create$4;
function getIn
getIn: <C = any>( schema: any, path: string, value?: any, context?: C) => { schema: ISchema<any> | Reference<any>; parent: any; parentPath: string };
function isSchema
isSchema: (obj: any) => obj is ISchema<any, any, any, any>;
function lazy
lazy: < TSchema extends ISchema<any, TContext, any, any>, TContext extends AnyObject = AnyObject>( builder: (value: any, options: ResolveOptions<TContext>) => TSchema) => Lazy<InferType<TSchema>, TContext, any>;
function mixed
mixed: typeof create$8;
function number
number: typeof create$5;
function object
object: typeof create$3;
function printValue
printValue: (value: any, quoteStrings?: boolean) => any;
function reach
reach: <P extends string, S extends ISchema<any, any, any, any>>( obj: S, path: P, value?: any, context?: any) => Reference<Get<InferType<S>, P>> | ISchema<Get<InferType<S>, P>, S['__context']>;
function ref
ref: <TValue = unknown>( key: string, options?: ReferenceOptions<TValue>) => Reference<TValue>;
function setLocale
setLocale: (custom: LocaleObject) => void;
function string
string: typeof create$6;
function tuple
tuple: typeof create$1;
Classes
class ArraySchema
class ArraySchema< TIn extends any[] | null | undefined, TContext, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TIn, TContext, TDefault, TFlags> {}
constructor
constructor(type?: ISchema<InnerType<TIn>, TContext, any, any>);
property innerType
readonly innerType?: ISchema<InnerType<TIn>, TContext, any, any>;
property spec
spec: ArraySchemaSpec<TIn, TContext>;
method clone
clone: (spec?: SchemaSpec<any>) => this;
method compact
compact: (rejector?: RejectorFn) => this;
method concat
concat: { <IIn extends any[], IC, ID, IF extends Flags>( schema: ArraySchema<IIn, IC, ID, IF> ): ArraySchema< Concat<TIn, IIn>, TContext & IC, Extract<IF, 'd'> extends never ? TDefault : ID, TFlags | IF >; (schema: this): this;};
method describe
describe: (options?: ResolveOptions<TContext>) => SchemaInnerTypeDescription;
method ensure
ensure: () => ArraySchema<TIn, TContext, TIn, ToggleDefault<TFlags, TIn>>;
method json
json: () => this;
Parse an input JSON string to an object
method length
length: ( length: number | Reference<number>, message?: Message<{ length: number }>) => this;
method max
max: ( max: number | Reference<number>, message?: Message<{ max: number }>) => this;
method min
min: ( min: number | Reference<number>, message?: Message<{ min: number }>) => this;
method of
of: <U>( schema: ISchema<U, TContext>) => ArraySchema<U[] | Optionals<TIn>, TContext, TFlags>;
class BooleanSchema
class BooleanSchema< TType extends Maybe<boolean> = boolean | undefined, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TType, TContext, TDefault, TFlags> {}
constructor
constructor();
method default
default: <D extends TType>( def: DefaultThunk<D, TContext>) => BooleanSchema<TType, TContext, D, ToggleDefault<TFlags, D>>;
method defined
defined: ( msg?: Message) => BooleanSchema<Defined<TType>, TContext, TDefault, TFlags>;
method isFalse
isFalse: ( message?: Message<any> | undefined) => BooleanSchema<false | Optionals<TType>, TContext, TFlags>;
method isTrue
isTrue: ( message?: Message<any> | undefined) => BooleanSchema<true | Optionals<TType>, TContext, TFlags>;
method nonNullable
nonNullable: ( msg?: Message) => BooleanSchema<NotNull<TType>, TContext, TDefault, TFlags>;
method notRequired
notRequired: () => BooleanSchema<Maybe<TType>, TContext, TDefault, TFlags>;
method nullable
nullable: () => BooleanSchema<TType | null, TContext, TDefault, TFlags>;
method optional
optional: () => BooleanSchema<TType | undefined, TContext, TDefault, TFlags>;
method required
required: ( msg?: Message) => BooleanSchema<NonNullable<TType>, TContext, TDefault, TFlags>;
method strip
strip: { (enabled: false): BooleanSchema< TType, TContext, TDefault, UnsetFlag<TFlags, 's'> >; (enabled?: true): BooleanSchema< TType, TContext, TDefault, SetFlag<TFlags, 's'> >;};
class DateSchema
class DateSchema< TType extends Maybe<Date> = Date | undefined, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TType, TContext, TDefault, TFlags> {}
constructor
constructor();
property INVALID_DATE
static INVALID_DATE: Date;
method max
max: ( max: unknown | Reference, message?: Message<{ max: string | Date }>) => this;
method min
min: ( min: unknown | Reference<Date>, message?: Message<{ min: string | Date }>) => this;
class Lazy
class Lazy<T, TContext = AnyObject, TFlags extends Flags = any> implements ISchema<T, TContext, TFlags, undefined> {}
constructor
constructor(builder: any);
property spec
spec: LazySpec;
property type
type: string;
method asNestedTest
asNestedTest: (config: NestedTestConfig) => RunTest;
method cast
cast: { (value: any, options?: CastOptions$1<TContext>): T; (value: any, options?: CastOptionalityOptions<TContext>): T;};
method clone
clone: (spec?: Partial<LazySpec>) => Lazy<T, TContext, TFlags>;
method describe
describe: ( options?: ResolveOptions<TContext>) => SchemaLazyDescription | SchemaFieldDescription;
method isValid
isValid: (value: any, options?: ValidateOptions<TContext>) => Promise<boolean>;
method isValidSync
isValidSync: (value: any, options?: ValidateOptions<TContext>) => boolean;
method meta
meta: { (): Record<string, unknown> | undefined; (obj: Record<string, unknown>): Lazy<T, TContext, TFlags>;};
method optional
optional: () => Lazy<T | undefined, TContext, TFlags>;
method resolve
resolve: ( options: ResolveOptions<TContext>) => Schema<T, TContext, undefined, TFlags>;
method validate
validate: (value: any, options?: ValidateOptions<TContext>) => Promise<T>;
method validateAt
validateAt: ( path: string, value: any, options?: ValidateOptions<TContext>) => Promise<any>;
method validateSync
validateSync: (value: any, options?: ValidateOptions<TContext>) => T;
method validateSyncAt
validateSyncAt: ( path: string, value: any, options?: ValidateOptions<TContext>) => any;
class MixedSchema
class MixedSchema< TType extends Maybe<AnyPresentValue> = AnyPresentValue | undefined, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TType, TContext, TDefault, TFlags> {}
constructor
constructor(spec?: MixedOptions<TType> | TypeGuard<TType>);
class NumberSchema
class NumberSchema< TType extends Maybe<number> = number | undefined, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TType, TContext, TDefault, TFlags> {}
constructor
constructor();
method integer
integer: (message?: Message<any>) => this;
method lessThan
lessThan: ( less: number | Reference<number>, message?: Message<{ less: number }>) => this;
method max
max: ( max: number | Reference<number>, message?: Message<{ max: number }>) => this;
method min
min: ( min: number | Reference<number>, message?: Message<{ min: number }>) => this;
method moreThan
moreThan: ( more: number | Reference<number>, message?: Message<{ more: number }>) => this;
method negative
negative: (msg?: Message<{ less: number }>) => this;
method positive
positive: (msg?: Message<{ more: number }>) => this;
method round
round: (method?: 'ceil' | 'floor' | 'round' | 'trunc') => this;
method truncate
truncate: () => this;
class ObjectSchema
class ObjectSchema< TIn extends Maybe<AnyObject>, TContext = AnyObject, TDefault = any, TFlags extends Flags = ''> extends Schema<MakeKeysOptional<TIn>, TContext, TDefault, TFlags> {}
constructor
constructor(spec?: Shape<TIn, TContext>);
property fields
fields: Shape<NonNullable<TIn>, TContext>;
property spec
spec: ObjectSchemaSpec;
method camelCase
camelCase: () => this;
method clone
clone: (spec?: Partial<ObjectSchemaSpec>) => this;
method concat
concat: { <IIn extends AnyObject, IC, ID, IF extends Flags>( schema: ObjectSchema<IIn, IC, ID, IF> ): ObjectSchema< ConcatObjectTypes<TIn, IIn>, TContext & IC, Extract<IF, 'd'> extends never ? TDefault extends AnyObject ? ID extends AnyObject ? _<ConcatObjectTypes<TDefault, ID>> : ID : ID : ID, TFlags | IF >; (schema: this): this;};
method constantCase
constantCase: () => this;
method deepPartial
deepPartial: () => ObjectSchema<PartialDeep<TIn>, TContext, TDefault, TFlags>;
method describe
describe: (options?: ResolveOptions<TContext>) => SchemaObjectDescription;
method exact
exact: (message?: Message) => this;
Similar to
noUnknown
but only validates that an object is the right shape without stripping the unknown keys
method from
from: (from: string, to: keyof TIn, alias?: boolean) => this;
method json
json: () => this;
Parse an input JSON string to an object
method noUnknown
noUnknown: { (message?: Message): this; (noAllow: boolean, message?: Message<any>): this;};
method omit
omit: <TKey extends keyof TIn>( keys: readonly TKey[]) => ObjectSchema< { [K in Exclude<keyof TIn, TKey>]: TIn[K] }, TContext, TDefault, TFlags>;
method partial
partial: () => ObjectSchema<Partial<TIn>, TContext, TDefault, TFlags>;
method pick
pick: <TKey extends keyof TIn>( keys: readonly TKey[]) => ObjectSchema<{ [K in TKey]: TIn[K] }, TContext, TDefault, TFlags>;
method shape
shape: <U extends ObjectShape>( additions: U, excludes?: readonly [string, string][]) => ObjectSchema< | _< { [P in keyof TIn]: P extends keyof U ? TypeFromShape<U, TContext>[P] : TIn[P]; } & TypeFromShape<U, TContext> > | _<Extract<TIn, null>>, TContext, Extract<TFlags, 'd'> extends never ? _<TDefault & DefaultFromShape<U>> : TDefault, TFlags>;
method snakeCase
snakeCase: () => this;
method stripUnknown
stripUnknown: () => this;
method transformKeys
transformKeys: (fn: (key: string) => string) => this;
method unknown
unknown: (allow?: boolean, message?: Message<{ unknown: string[] }>) => this;
class Reference
class Reference<TValue = unknown> {}
constructor
constructor(key: string, options?: ReferenceOptions<TValue>);
property getter
readonly getter: (data: unknown) => unknown;
property isContext
readonly isContext: boolean;
property isSibling
readonly isSibling: boolean;
property isValue
readonly isValue: boolean;
property key
readonly key: string;
property map
readonly map?: (value: unknown) => TValue;
property path
readonly path: any;
method cast
cast: (value: any, options?: { parent?: {}; context?: {} }) => TValue;
Parameter value
Parameter options
Parameter
{Object=} options.context
Parameter
{Object=} options.parent
method describe
describe: () => SchemaRefDescription;
method getValue
getValue: (value: any, parent?: {}, context?: {}) => TValue;
method isRef
static isRef: (value: any) => value is Reference<unknown>;
method resolve
resolve: () => this;
method toString
toString: () => string;
class Schema
abstract class Schema< TType = any, TContext = any, TDefault = any, TFlags extends Flags = ''> implements ISchema<TType, TContext, TFlags, TDefault> {}
constructor
constructor(options: SchemaOptions<TType, any>);
property deps
readonly deps: readonly string[];
property exclusiveTests
protected exclusiveTests: Record<string, boolean>;
property spec
spec: SchemaSpec<any>;
property tests
tests: Test[];
property transforms
transforms: TransformFunction<AnySchema<any, any, any, Flags>>[];
property type
readonly type: string;
method asNestedTest
asNestedTest: ({ key, index, parent, parentPath, originalParent, options,}: NestedTestConfig) => RunTest;
method cast
cast: { (value: any, options?: CastOptions$1<TContext>): this['__outputType']; ( value: any, options: CastOptionalityOptions<TContext> ): this['__outputType'];};
Run the configured transform pipeline over an input value.
method clone
clone: (spec?: Partial<SchemaSpec<any>>) => this;
method concat
concat: { (schema: this): this; (schema: AnySchema<any, any, any, Flags>): AnySchema<any, any, any, Flags>;};
method default
default: (def: DefaultThunk<any>) => any;
method defined
defined: (message?: Message<any>) => any;
method describe
describe: (options?: ResolveOptions<TContext>) => SchemaDescription;
Return a serialized description of the schema including validations, flags, types etc.
Parameter options
Provide any needed context for resolving runtime schema alterations (lazy, when conditions, etc).
method getDefault
getDefault: (options?: ResolveOptions<TContext>) => TDefault;
method isType
isType: (v: unknown) => v is TType;
method isValid
isValid: (value: any, options?: ValidateOptions<TContext>) => Promise<boolean>;
method isValidSync
isValidSync: ( value: any, options?: ValidateOptions<TContext>) => value is this['__outputType'];
method label
label: (label: string) => this;
method meta
meta: { (): SchemaMetadata | undefined; (obj: Record<PropertyKey, any>): this };
method nonNullable
nonNullable: (message?: Message<any>) => any;
method notOneOf
notOneOf: <U extends TType>( enums: ReadonlyArray<Maybe<U> | Reference>, message?: Message<{ values: any }>) => this;
method notRequired
notRequired: () => any;
method nullability
protected nullability: (nullable: boolean, message?: Message<any>) => this;
method nullable
nullable: () => any;
method oneOf
oneOf: { <U extends TType>( enums: ReadonlyArray<U | Reference>, message?: Message<{ values: any }> ): this; ( enums: readonly (Reference<unknown> | TType)[], message: Message<{ values: any }> ): any;};
method optional
optional: () => any;
method optionality
protected optionality: (optional: boolean, message?: Message<any>) => this;
method required
required: (message?: Message<any>) => any;
method resolve
resolve: (options: ResolveOptions<TContext>) => this;
method resolveOptions
protected resolveOptions: <T extends InternalOptions<any>>(options: T) => T;
method runTests
protected runTests: ( runOptions: TestRunOptions, panic: (err: Error, value: unknown) => void, next: (errors: ValidationError[], value: unknown) => void) => void;
Executes a set of validations, either schema, produced Tests or a nested schema validate result.
method strict
strict: (isStrict?: boolean) => this;
method strip
strip: (strip?: boolean) => any;
method test
test: { (options: TestConfig<this['__outputType'], TContext>): this; (test: TestFunction<this['__outputType'], TContext>): this; (name: string, test: TestFunction<this['__outputType'], TContext>): this; ( name: string, message: Message<any>, test: TestFunction<this['__outputType'], TContext> ): this;};
Adds a test function to the schema's queue of tests. tests can be exclusive or non-exclusive.
- exclusive tests, will replace any existing tests of the same name. - non-exclusive: can be stacked
If a non-exclusive test is added to a schema with an exclusive test of the same name the exclusive test is removed and further tests of the same name will be stacked.
If an exclusive test is added to a schema with non-exclusive tests of the same name the previous tests are removed and further tests of the same name will replace each other.
method transform
transform: (fn: TransformFunction<this>) => this;
method typeError
typeError: (message: Message) => this;
method validate
validate: ( value: any, options?: ValidateOptions<TContext>) => Promise<this['__outputType']>;
method validateSync
validateSync: ( value: any, options?: ValidateOptions<TContext>) => this['__outputType'];
method when
when: { (builder: ConditionBuilder<this>): this; (keys: string | string[], builder: ConditionBuilder<this>): this; (options: ConditionConfig<this>): this; (keys: string | string[], options: ConditionConfig<this>): this;};
method withMutation
withMutation: <T>(fn: (schema: this) => T) => T;
class StringSchema
class StringSchema< TType extends Maybe<string> = string | undefined, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TType, TContext, TDefault, TFlags> {}
constructor
constructor();
method datetime
datetime: (options?: DateTimeOptions | DateTimeOptions['message']) => this;
method email
email: (message?: Message<{ regex: RegExp }>) => this;
method ensure
ensure: () => StringSchema<NonNullable<TType>>;
method length
length: ( length: number | Reference<number>, message?: Message<{ length: number }>) => this;
method lowercase
lowercase: (message?: Message<any>) => this;
method matches
matches: ( regex: RegExp, options?: MatchOptions | MatchOptions['message']) => this;
method max
max: ( max: number | Reference<number>, message?: Message<{ max: number }>) => this;
method min
min: ( min: number | Reference<number>, message?: Message<{ min: number }>) => this;
method trim
trim: (message?: Message<any>) => this;
method uppercase
uppercase: (message?: Message<any>) => this;
method url
url: (message?: Message<{ regex: RegExp }>) => this;
method uuid
uuid: (message?: Message<{ regex: RegExp }>) => this;
class TupleSchema
class TupleSchema< TType extends Maybe<AnyTuple> = AnyTuple | undefined, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TType, TContext, TDefault, TFlags> {}
constructor
constructor( schemas: [ISchema<any, any, any, any>, ...ISchema<any, any, any, any>[]]);
property spec
spec: TupleSchemaSpec<TType>;
method describe
describe: (options?: ResolveOptions<TContext>) => SchemaInnerTypeDescription;
class ValidationError
class ValidationError extends Error {}
constructor
constructor( errorOrErrors: string | ValidationError | readonly ValidationError[], value?: any, field?: string, type?: string, disableStack?: boolean);
property [Symbol.toStringTag]
[Symbol.toStringTag]: string;
property errors
errors: string[];
property inner
inner: ValidationError[];
property params
params?: Params;
property path
path?: string;
property type
type?: string;
property value
value: any;
method [Symbol.hasInstance]
static [Symbol.hasInstance]: (inst: any) => boolean;
method formatError
static formatError: (message: unknown, params: Params) => any;
method isError
static isError: (err: any) => err is ValidationError;
Interfaces
interface ArraySchema
interface ArraySchema< TIn extends any[] | null | undefined, TContext, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TIn, TContext, TDefault, TFlags> {}
method default
default: <D extends TIn>( def: DefaultThunk<D, TContext>) => ArraySchema<TIn, TContext, D, ToggleDefault<TFlags, D>>;
method defined
defined: ( msg?: Message) => ArraySchema<Defined<TIn>, TContext, TDefault, TFlags>;
method nonNullable
nonNullable: ( msg?: Message) => ArraySchema<NotNull<TIn>, TContext, TDefault, TFlags>;
method notRequired
notRequired: () => ArraySchema<Maybe<TIn>, TContext, TDefault, TFlags>;
method nullable
nullable: (msg?: Message) => ArraySchema<TIn | null, TContext, TDefault, TFlags>;
method optional
optional: () => ArraySchema<TIn | undefined, TContext, TDefault, TFlags>;
method required
required: ( msg?: Message) => ArraySchema<NonNullable<TIn>, TContext, TDefault, TFlags>;
method strip
strip: { (enabled: false): ArraySchema< TIn, TContext, TDefault, UnsetFlag<TFlags, 's'> >; (enabled?: true): ArraySchema<TIn, TContext, TDefault, SetFlag<TFlags, 's'>>;};
interface CustomSchemaMetadata
interface CustomSchemaMetadata {}
interface DateSchema
interface DateSchema< TType extends Maybe<Date>, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TType, TContext, TDefault, TFlags> {}
method concat
concat: <TOther extends DateSchema<any, any, undefined, ''>>( schema: TOther) => TOther;
method default
default: <D extends TType>( def: DefaultThunk<D, TContext>) => DateSchema<TType, TContext, D, ToggleDefault<TFlags, D>>;
method defined
defined: ( msg?: Message) => DateSchema<Defined<TType>, TContext, TDefault, TFlags>;
method nonNullable
nonNullable: ( msg?: Message) => DateSchema<NotNull<TType>, TContext, TDefault, TFlags>;
method notRequired
notRequired: () => DateSchema<Maybe<TType>, TContext, TDefault, TFlags>;
method nullable
nullable: ( msg?: Message) => DateSchema<TType | null, TContext, TDefault, TFlags>;
method optional
optional: () => DateSchema<TType | undefined, TContext, TDefault, TFlags>;
method required
required: ( msg?: Message) => DateSchema<NonNullable<TType>, TContext, TDefault, TFlags>;
method strip
strip: { (enabled: false): DateSchema< TType, TContext, TDefault, UnsetFlag<TFlags, 's'> >; (enabled?: true): DateSchema< TType, TContext, TDefault, SetFlag<TFlags, 's'> >;};
interface ISchema
interface ISchema<T, C = any, F extends Flags = any, D = any> {}
method asNestedTest
asNestedTest: (config: NestedTestConfig) => Test;
method cast
cast: { (value: any, options?: CastOptions$1<C>): T; (value: any, options: CastOptionalityOptions<C>): T;};
method describe
describe: (options?: ResolveOptions<C>) => SchemaFieldDescription;
method resolve
resolve: (options: ResolveOptions<C>) => ISchema<T, C, F>;
method validate
validate: (value: any, options?: ValidateOptions<C>) => Promise<T>;
interface LocaleObject
interface LocaleObject {}
interface MessageParams
interface MessageParams {}
property label
label: string;
property originalPath
originalPath: string;
property originalValue
originalValue: any;
property path
path: string;
property spec
spec: SchemaSpec<any> & Record<string, unknown>;
property type
type: string;
property value
value: any;
interface MixedOptions
interface MixedOptions<TType> {}
interface MixedSchema
interface MixedSchema< TType extends Maybe<AnyPresentValue> = AnyPresentValue | undefined, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TType, TContext, TDefault, TFlags> {}
method concat
concat: { <IT, IC, ID, IF extends Flags>( schema: MixedSchema<IT, IC, ID, IF> ): MixedSchema<Concat<TType, IT>, TContext & IC, ID, TFlags | IF>; <IT, IC, ID, IF extends Flags>(schema: Schema<IT, IC, ID, IF>): MixedSchema< Concat<TType, IT>, TContext & IC, ID, TFlags | IF >; (schema: this): this;};
method default
default: <D extends TType>( def: DefaultThunk<D, TContext>) => MixedSchema<TType, TContext, D, ToggleDefault<TFlags, D>>;
method defined
defined: ( msg?: Message) => MixedSchema<Defined<TType>, TContext, TDefault, TFlags>;
method nonNullable
nonNullable: ( msg?: Message) => MixedSchema<Exclude<TType, null>, TContext, TDefault, TFlags>;
method notRequired
notRequired: () => MixedSchema<Maybe<TType>, TContext, TDefault, TFlags>;
method nullable
nullable: ( msg?: Message) => MixedSchema<TType | null, TContext, TDefault, TFlags>;
method optional
optional: () => MixedSchema<TType | undefined, TContext, TDefault, TFlags>;
method required
required: ( msg?: Message) => MixedSchema<NonNullable<TType>, TContext, TDefault, TFlags>;
method strip
strip: { (enabled: false): MixedSchema< TType, TContext, TDefault, UnsetFlag<TFlags, 's'> >; (enabled?: true): MixedSchema< TType, TContext, TDefault, SetFlag<TFlags, 's'> >;};
interface NumberSchema
interface NumberSchema< TType extends Maybe<number> = number | undefined, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TType, TContext, TDefault, TFlags> {}
method concat
concat: { <UType extends number, UContext, UFlags extends Flags, UDefault>( schema: NumberSchema<UType, UContext, UDefault, UFlags> ): NumberSchema< Concat<TType, UType>, TContext & UContext, UDefault, TFlags | UFlags >; (schema: this): this;};
method default
default: <D extends TType>( def: DefaultThunk<D, TContext>) => NumberSchema<TType, TContext, D, ToggleDefault<TFlags, D>>;
method defined
defined: ( msg?: Message) => NumberSchema<Defined<TType>, TContext, TDefault, TFlags>;
method nonNullable
nonNullable: ( msg?: Message) => NumberSchema<NotNull<TType>, TContext, TDefault, TFlags>;
method notRequired
notRequired: () => NumberSchema<Maybe<TType>, TContext, TDefault, TFlags>;
method nullable
nullable: ( msg?: Message) => NumberSchema<TType | null, TContext, TDefault, TFlags>;
method optional
optional: () => NumberSchema<TType | undefined, TContext, TDefault, TFlags>;
method required
required: ( msg?: Message) => NumberSchema<NonNullable<TType>, TContext, TDefault, TFlags>;
method strip
strip: { (enabled: false): NumberSchema< TType, TContext, TDefault, UnsetFlag<TFlags, 's'> >; (enabled?: true): NumberSchema< TType, TContext, TDefault, SetFlag<TFlags, 's'> >;};
interface ObjectSchema
interface ObjectSchema< TIn extends Maybe<AnyObject>, TContext = AnyObject, TDefault = any, TFlags extends Flags = ''> extends Schema<MakeKeysOptional<TIn>, TContext, TDefault, TFlags> {}
method default
default: <D extends AnyObject>( def: DefaultThunk<D, TContext>) => ObjectSchema<TIn, TContext, D, ToggleDefault<TFlags, 'd'>>;
method defined
defined: ( msg?: Message) => ObjectSchema<Defined<TIn>, TContext, TDefault, TFlags>;
method nonNullable
nonNullable: ( msg?: Message) => ObjectSchema<NotNull<TIn>, TContext, TDefault, TFlags>;
method notRequired
notRequired: () => ObjectSchema<Maybe<TIn>, TContext, TDefault, TFlags>;
method nullable
nullable: ( msg?: Message) => ObjectSchema<TIn | null, TContext, TDefault, TFlags>;
method optional
optional: () => ObjectSchema<TIn | undefined, TContext, TDefault, TFlags>;
method required
required: ( msg?: Message) => ObjectSchema<NonNullable<TIn>, TContext, TDefault, TFlags>;
method strip
strip: { (enabled: false): ObjectSchema< TIn, TContext, TDefault, UnsetFlag<TFlags, 's'> >; (enabled?: true): ObjectSchema< TIn, TContext, TDefault, SetFlag<TFlags, 's'> >;};
interface Schema
interface Schema< TType = any, TContext = any, TDefault = any, TFlags extends Flags = ''> {}
property equals
equals: Schema['oneOf'];
property is
is: Schema['oneOf'];
property nope
nope: Schema['notOneOf'];
property not
not: Schema['notOneOf'];
method validateAt
validateAt: ( path: string, value: any, options?: ValidateOptions<TContext>) => Promise<any>;
method validateSyncAt
validateSyncAt: ( path: string, value: any, options?: ValidateOptions<TContext>) => any;
interface SchemaDescription
interface SchemaDescription {}
property default
default?: unknown;
property label
label?: string;
property meta
meta?: SchemaMetadata;
property notOneOf
notOneOf: unknown[];
property nullable
nullable: boolean;
property oneOf
oneOf: unknown[];
property optional
optional: boolean;
property tests
tests: Array<{ name?: string; params: ExtraParams | undefined;}>;
property type
type: string;
interface SchemaInnerTypeDescription
interface SchemaInnerTypeDescription extends SchemaDescription {}
property innerType
innerType?: SchemaFieldDescription | SchemaFieldDescription[];
interface SchemaLazyDescription
interface SchemaLazyDescription {}
interface SchemaObjectDescription
interface SchemaObjectDescription extends SchemaDescription {}
property fields
fields: Record<string, SchemaFieldDescription>;
interface SchemaRefDescription
interface SchemaRefDescription {}
interface StringSchema
interface StringSchema< TType extends Maybe<string> = string | undefined, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TType, TContext, TDefault, TFlags> {}
method concat
concat: { <UType extends string, UContext, UDefault, UFlags extends Flags>( schema: StringSchema<UType, UContext, UDefault, UFlags> ): StringSchema< Concat<TType, UType>, TContext & UContext, UDefault, TFlags | UFlags >; (schema: this): this;};
method default
default: <D extends TType>( def: DefaultThunk<D, TContext>) => StringSchema<TType, TContext, D, ToggleDefault<TFlags, D>>;
method defined
defined: ( msg?: Message) => StringSchema<Defined<TType>, TContext, TDefault, TFlags>;
method nonNullable
nonNullable: ( msg?: Message) => StringSchema<NotNull<TType>, TContext, TDefault, TFlags>;
method notRequired
notRequired: () => StringSchema<Maybe<TType>, TContext, TDefault, TFlags>;
method nullable
nullable: ( msg?: Message) => StringSchema<TType | null, TContext, TDefault, TFlags>;
method oneOf
oneOf: { <U extends TType>( arrayOfValues: ReadonlyArray<U | Reference<U>>, message?: MixedLocale['oneOf'] ): StringSchema<U | Optionals<TType>, TContext, TDefault, TFlags>; ( enums: readonly (Reference<unknown> | TType)[], message?: Message<{ values: any }> ): this;};
method optional
optional: () => StringSchema<TType | undefined, TContext, TDefault, TFlags>;
method required
required: ( msg?: Message) => StringSchema<NonNullable<TType>, TContext, TDefault, TFlags>;
method strip
strip: { (enabled: false): StringSchema< TType, TContext, TDefault, UnsetFlag<TFlags, 's'> >; (enabled?: true): StringSchema< TType, TContext, TDefault, SetFlag<TFlags, 's'> >;};
interface TupleSchema
interface TupleSchema< TType extends Maybe<AnyTuple> = AnyTuple | undefined, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = ''> extends Schema<TType, TContext, TDefault, TFlags> {}
method concat
concat: <TOther extends TupleSchema<any, any, undefined, ''>>( schema: TOther) => TOther;
method default
default: <D extends TType>( def: DefaultThunk<D, TContext>) => TupleSchema<TType, TContext, D, ToggleDefault<TFlags, D>>;
method defined
defined: ( msg?: Message) => TupleSchema<Defined<TType>, TContext, TDefault, TFlags>;
method nonNullable
nonNullable: ( msg?: Message) => TupleSchema<NotNull<TType>, TContext, TDefault, TFlags>;
method notRequired
notRequired: () => TupleSchema<Maybe<TType>, TContext, TDefault, TFlags>;
method nullable
nullable: ( msg?: Message) => TupleSchema<TType | null, TContext, TDefault, TFlags>;
method optional
optional: () => TupleSchema<TType | undefined, TContext, TDefault, TFlags>;
method required
required: ( msg?: Message) => TupleSchema<NonNullable<TType>, TContext, TDefault, TFlags>;
method strip
strip: { (enabled: false): TupleSchema< TType, TContext, TDefault, UnsetFlag<TFlags, 's'> >; (enabled?: true): TupleSchema< TType, TContext, TDefault, SetFlag<TFlags, 's'> >;};
interface ValidateOptions
interface ValidateOptions<TContext = {}> {}
property abortEarly
abortEarly?: boolean;
Return from validation methods on the first error rather than after all validations run. Default - true
property context
context?: TContext;
Any context needed for validating schema conditions (see: when())
property disableStackTrace
disableStackTrace?: boolean;
When true ValidationError instance won't include stack trace information. Default - false
property recursive
recursive?: boolean;
When false validations will not descend into nested schema (relevant for objects or arrays). Default - true
property strict
strict?: boolean;
Only validate the input, skipping type casting and transformation. Default - false
property stripUnknown
stripUnknown?: boolean;
Remove unspecified keys from objects. Default - false
Type Aliases
type AnyMessageParams
type AnyMessageParams = MessageParams & ExtraParams;
type AnyObject
type AnyObject = { [k: string]: any;};
type AnyObjectSchema
type AnyObjectSchema = ObjectSchema<any, any, any, any>;
type AnySchema
type AnySchema<TType = any, C = any, D = any, F extends Flags = Flags> = Schema< TType, C, D, F>;
type Asserts
type InferType<T extends ISchema<any, any>> = T['__outputType'];
type CastOptions
type CastOptions = Omit<CastOptions$1, 'path' | 'resolved'>;
type CreateErrorOptions
type CreateErrorOptions = { path?: string; message?: Message<any>; params?: ExtraParams; type?: string; disableStackTrace?: boolean;};
type DefaultFromShape
type DefaultFromShape<Shape extends ObjectShape> = { [K in keyof Shape]: Shape[K] extends ISchema<any> ? Shape[K]['__default'] : undefined;};
type DefaultThunk
type DefaultThunk<T, C = any> = T | ((options?: ResolveOptions<C>) => T);
type Defined
type Defined<T> = T extends undefined ? never : T;
type Flags
type Flags = 's' | 'd' | '';
type InferType
type InferType<T extends ISchema<any, any>> = T['__outputType'];
type MakePartial
type MakePartial<T extends object> = { [k in OptionalKeys<T> as T[k] extends never ? never : k]?: T[k];} & { [k in RequiredKeys<T> as T[k] extends never ? never : k]: T[k];};
type Maybe
type Maybe<T> = T | null | undefined;
type Message
type Message<Extra extends Record<string, unknown> = any> = | string | ((params: Extra & MessageParams) => unknown) | Record<PropertyKey, unknown>;
type MixedTypeGuard
type TypeGuard<TType> = (value: any) => value is NonNullable<TType>;
type NotNull
type NotNull<T> = T extends null ? never : T;
type ObjectShape
type ObjectShape = { [k: string]: ISchema<any> | Reference;};
type Optionals
type Optionals<T> = Extract<T, null | undefined>;
type SchemaFieldDescription
type SchemaFieldDescription = | SchemaDescription | SchemaRefDescription | SchemaObjectDescription | SchemaInnerTypeDescription | SchemaLazyDescription;
type SchemaMetadata
type SchemaMetadata = keyof CustomSchemaMetadata extends never ? Record<PropertyKey, any> : CustomSchemaMetadata;
type SetFlag
type SetFlag<Old extends Flags, F extends Flags> = Exclude<Old, ''> | F;
type TestConfig
type TestConfig<TValue = unknown, TContext = {}> = { name?: string; message?: Message<any>; test: TestFunction<TValue, TContext>; params?: ExtraParams; exclusive?: boolean; skipAbsent?: boolean;};
type TestContext
type TestContext<TContext = {}> = { path: string; options: ValidateOptions<TContext>; originalValue: any; parent: any; from?: Array<{ schema: ISchema<any, TContext>; value: any; }>; schema: any; resolve: <T>(value: T | Reference<T>) => T; createError: (params?: CreateErrorOptions) => ValidationError;};
type TestFunction
type TestFunction<T = unknown, TContext = {}> = ( this: TestContext<TContext>, value: T, context: TestContext<TContext>) => void | boolean | ValidationError | Promise<boolean | ValidationError>;
type TestOptions
type TestOptions<TSchema extends AnySchema = AnySchema> = { value: any; path?: string; options: InternalOptions; originalValue: any; schema: TSchema;};
type ToggleDefault
type ToggleDefault<F extends Flags, D> = Preserve<D, undefined> extends never ? SetFlag<F, 'd'> : UnsetFlag<F, 'd'>;
type TypeFromShape
type TypeFromShape<S extends ObjectShape, _C> = { [K in keyof S]: S[K] extends ISchema<any> ? ResolveStrip<S[K]> : S[K] extends Reference<infer T> ? T : unknown;};
type UnsetFlag
type UnsetFlag<Old extends Flags, F extends Flags> = Exclude<Old, F> extends never ? '' : Exclude<Old, F>;
Namespaces
namespace boolean
namespace boolean {}
variable prototype
var prototype: BooleanSchema<any, any, any, any>;
namespace date
namespace date {}
variable INVALID_DATE
var INVALID_DATE: Date;
variable prototype
var prototype: DateSchema<any, any, any, any>;
namespace number
namespace number {}
variable prototype
var prototype: NumberSchema<any, any, any, any>;
namespace object
namespace object {}
variable prototype
var prototype: ObjectSchema<any, any, any, any>;
Package Files (1)
Dependencies (4)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/yup
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/yup)
- HTML<a href="https://www.jsdocs.io/package/yup"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 6911 ms. - Missing or incorrect documentation? Open an issue for this package.