Conversation with Merlin [email protected] · Mon Nov 20 2023

yup

Yup is a schema builder for runtime value parsing and validation. It allows you to define a schema, transform a value to match, assert the shape of an existing value, or do both. Yup schema are highly expressive and capable of modeling complex, interdependent validations or value transformation. Some of the key features of Yup include its concise yet expressive schema interface, powerful TypeScript support, built-in async validation support, extensibility to add your own type-safe methods and schema, as well as rich error details to facilitate debugging.

To get started with Yup, schemas are comprised of parsing actions (transforms) as well as assertions (tests) about the input value. You can validate an input value to parse it and run the configured set of assertions and chain together methods to build a schema. You can also use a schema to coerce or "cast" an input value into the correct type, and optionally transform that value into more concrete and specific values, without making further assertions.

For example, you can define a user schema with attributes such as name, age, email, website, and created, and then parse and assert its validity.

Here's a basic example of using Yup to create a user schema:

import { object, string, number, date, InferType } from 'yup'; let userSchema = object({ name: string().required(), age: number().required().positive().integer(), email: string().email(), website: string().url().nullable(), createdOn: date().default(() => new Date()), }); // Parse and assert validity const user = await userSchema.validate(await fetchUser()); type User = InferType<typeof userSchema>; // Use a schema to coerce or "cast" an input value into the correct type const parsedUser = userSchema.cast({ name: 'jimmy', age: '24', createdOn: '2014-09-23T19:25:25Z' });

This is just a basic overview of Yup and how it can be used for runtime value parsing and validation. If you have specific questions or need further assistance with Yup, feel free to ask!

Yup Yup is a schema builder for runtime value parsing and validation. Define a schema, transform a value to match, assert the shape of an existing value, or both. Yup schema are extremely expressive and allow modeling complex, interdependent validations, or value transformation. You are viewing docs for the v1.0.0 of yup, pre-v1 docs are available: here Killer Features: Concise yet expressive schema interface, equipped to model simple to complex data models Powerful TypeScript support. Infer static types from schema, or ensure schema correctly implement a type Built-in async validation support. Model server-side and client-side validation equally well Extensible: add your own type-safe methods and schema Rich error details, make debugging a breeze Getting Started Schema are comprised of parsing actions (transforms) as well as assertions (tests) about the input value. Validate an input value to parse it and run the configured set of assertions. Chain together methods to build a schema. import { object, string, number, date, InferType } from 'yup'; let userSchema = object({ name: string().required(), age: number().required().positive().integer(), email: string().email(), website: string().url().nullable(), createdOn: date().default(() => new Date()), }); // parse and assert validity const user = await userSchema.validate(await fetchUser()); type User = InferType<typeof userSchema>; /* { name: string; age: number; email?: string | undefined website?: string | null | undefined createdOn: Date }*/ Use a schema to coerce or "cast" an input value into the correct type, and optionally transform that value into more concrete and specific values, without making further assertions. // Attempts to coerce values to the correct type const parsedUser = userSchema.cast({ name: 'jimmy', age: '24', createdOn: '2014-09-23T19:25:25Z', }); // { name: 'jimmy', age: 24, createdOn: Date } Know that your input value is already parsed? You can "strictly" validate an input, and avoid the overhead of running parsing logic. // ValidationError "age is not a number" const parsedUser = await userSchema.validate( { name: 'jimmy', age: '24', }, { strict: true }, ); Table of Contents Schema basics Parsing: Transforms Validation: Tests Customizing errors Composition and Reuse TypeScript integration Schema defaults Ensuring a schema matches an existing type Extending built-in schema with new methods TypeScript configuration Error message customization localization and i18n API yup reach(schema: Schema, path: string, value?: object, context?: object): Schema addMethod(schemaType: Schema, name: string, method: ()=> Schema): void ref(path: string, options: { contextPrefix: string }): Ref lazy((value: any) => Schema): Lazy ValidationError(errors: string | Array<string>, value: any, path: string) Schema Schema.clone(): Schema Schema.label(label: string): Schema Schema.meta(metadata: SchemaMetadata): Schema Schema.describe(options?: ResolveOptions): SchemaDescription Schema.concat(schema: Schema): Schema Schema.validate(value: any, options?: object): Promise<InferType<Schema>, ValidationError> Schema.validateSync(value: any, options?: object): InferType<Schema> Schema.validateAt(path: string, value: any, options?: object): Promise<InferType<Schema>, ValidationError> Schema.validateSyncAt(path: string, value: any, options?: object): InferType<Schema> Schema.isValid(value: any, options?: object): Promise<boolean> Schema.isValidSync(value: any, options?: object): boolean Schema.cast(value: any, options = {}): InferType<Schema> Schema.isType(value: any): value is InferType<Schema> Schema.strict(enabled: boolean = false): Schema Schema.strip(enabled: boolean = true): Schema Schema.withMutation(builder: (current: Schema) => void): void Schema.default(value: any): Schema Schema.getDefault(options?: object): Any Schema.nullable(): Schema Schema.nonNullable(): Schema Schema.defined(): Schema Schema.optional(): Schema Schema.required(message?: string | function): Schema Schem

github.com

Yup Yup is a schema builder for runtime value parsing and validation. Define a schema, transform a value to match, assert the shape of an existing value, or both. Yup schema are extremely expressive and allow modeling complex, interdependent validations, or value transformation. You are viewing docs for the v1.0.0 of yup, pre-v1 docs are available: here Killer Features: Concise yet expressive schema interface, equipped to model simple to complex data models Powerful TypeScript support. Infer static types from schema, or ensure schema correctly implement a type Built-in async validation support. Model server-side and client-side validation equally well Extensible: add your own type-safe methods and schema Rich error details, make debugging a breeze Getting Started Schema are comprised of parsing actions (transforms) as well as assertions (tests) about the input value. Validate an input value to parse it and run the configured set of assertions. Chain together methods to build a schema. import { object, string, number, date, InferType } from 'yup'; let userSchema = object({ name: string().required(), age: number().required().positive().integer(), email: string().email(), website: string().url().nullable(), createdOn: date().default(() => new Date()), }); // parse and assert validity const user = await userSchema.validate(await fetchUser()); type User = InferType<typeof userSchema>; /* { name: string; age: number; email?: string | undefined website?: string | null | undefined createdOn: Date }*/ Use a schema to coerce or "cast" an input value into the correct type, and optionally transform that value into more concrete and specific values, without making further assertions. // Attempts to coerce values to the correct type const parsedUser = userSchema.cast({ name: 'jimmy', age: '24', createdOn: '2014-09-23T19:25:25Z', }); // { name: 'jimmy', age: 24, createdOn: Date } Know that your input value is already parsed? You can "strictly" validate an input, and avoid the overhead of running parsing logic. // ValidationError "age is not a number" const parsedUser = await userSchema.validate( { name: 'jimmy', age: '24', }, { strict: true }, ); Table of Contents Schema basics Parsing: Transforms Validation: Tests Customizing errors Composition and Reuse TypeScript integration Schema defaults Ensuring a schema matches an existing type Extending built-in schema with new methods TypeScript configuration Error message customization localization and i18n API yup reach(schema: Schema, path: string, value?: object, context?: object): Schema addMethod(schemaType: Schema, name: string, method: ()=> Schema): void ref(path: string, options: { contextPrefix: string }): Ref lazy((value: any) => Schema): Lazy ValidationError(errors: string | Array<string>, value: any, path: string) Schema Schema.clone(): Schema Schema.label(label: string): Schema Schema.meta(metadata: SchemaMetadata): Schema Schema.describe(options?: ResolveOptions): SchemaDescription Schema.concat(schema: Schema): Schema Schema.validate(value: any, options?: object): Promise<InferType<Schema>, ValidationError> Schema.validateSync(value: any, options?: object): InferType<Schema> Schema.validateAt(path: string, value: any, options?: object): Promise<InferType<Schema>, ValidationError> Schema.validateSyncAt(path: string, value: any, options?: object): InferType<Schema> Schema.isValid(value: any, options?: object): Promise<boolean> Schema.isValidSync(value: any, options?: object): boolean Schema.cast(value: any, options = {}): InferType<Schema> Schema.isType(value: any): value is InferType<Schema> Schema.strict(enabled: boolean = false): Schema Schema.strip(enabled: boolean = true): Schema Schema.withMutation(builder: (current: Schema) => void): void Schema.default(value: any): Schema Schema.getDefault(options?: object): Any Schema.nullable(): Schema Schema.nonNullable(): Schema Schema.defined(): Schema Schema.optional(): Schema Schema.required(message?: string | function): Schema Schema

npmjs.com

yupOrigin of yup1Form of yeah as an isolated or emphatic utterance, with p representing closing of the lips, creating, in effect, an unreleased labial stop (and perhaps also lowering the vowel); compare the parallel use of p in nopeAlso yep. Words Nearby yupYumpieYumpyyum-yumYung LoYunnanyupYupikyuppieyuppie diseaseyuppie fluyuppifyDictionary.com Unabridged Based on the Random House Unabridged Dictionary, Random House, Inc. 2023How to use yup in a sentenceyup, Evelyn and Donald Knapp are ordained Christian ministers suing for the right to discriminate.yup, it was right there, within that eight-plex apartment building, where the Ebola outbreak in Dallas refused to die.yup, former Defense Secretary Donald Rumsfeld compared President Obama to an ape.Asked about them backstage, Stinson allows an awkward pause, sips his drink and finally just says yup.Journals aren't interested in null results or "yup, we replicated that other study"; they want new studies with new findings.See yup departed the day that the syndicate took possession."yup," interrupted Miss Taylor, who had scarcely ceased talking since breakfast that morning.Mr. yup complies with the request, and responds by telegraph, "Me you trunkee you sendee."So the matter dropped, and See yup remained master of the situation.The outlaw grinned: "Make a mistake sometimes, same as other folksyup I picked him."British Dictionary definitions for yupsentence substitutean informal word for yesCollins English Dictionary - Complete & Unabridged 2012 Digital Edition William Collins Sons & Co. Ltd. 1979, 1986 HarperCollins Publishers 1998, 2000, 2003, 2005, 2006, 2007, 2009, 2012

dictionary.com