### Install Valext Package Source: https://github.com/gambonny/valext/blob/main/README.md Installs the valext package using pnpm. ```bash pnpm add @gambonny/valext ``` -------------------------------- ### Hono Signup Validation Example Source: https://github.com/gambonny/valext/blob/main/README.md Integrates valext with Hono's validator middleware for validating JSON request bodies in a signup route. Validation issues are logged using the Hono context's logger. ```typescript import { validator } from 'hono/validator' import { extract } from '@gambonny/valext' import { signupSchema } from './schemas' app.post( '/signup', validator('json', async (body, c) => { const { success, output } = extract(signupSchema).from(body, issues => c.var.logger.warn('validation failed', { issues }), ) return success ? output : c.text('Invalid input') }), ) ``` -------------------------------- ### extract(schema).parse(input) Source: https://github.com/gambonny/valext/blob/main/README.md Parses the input using the provided schema, identical to valibot.parse(). It will throw an error if the input is invalid. ```APIDOC ## extract(schema).parse(input) ### Description Parses the input using the provided schema, identical to valibot.parse(). It will throw an error if the input is invalid. This method is suitable for cases where invalid input should halt execution. ### Method Not applicable (SDK function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **schema**: The Valibot schema to use for validation. - **input**: The value to parse. ### Returns The validated and typed output if the input is valid. Throws an error if the input is invalid. ``` -------------------------------- ### extract(schema).safe(input, onError?) Source: https://github.com/gambonny/valext/blob/main/README.md Provides functionality similar to valibot.safeParse(), but allows for a callback to handle flattened errors. ```APIDOC ## extract(schema).safe(input, onError?) ### Description Provides functionality similar to valibot.safeParse(), but allows for a callback to handle flattened errors. This method is useful for scenarios where you want to catch validation errors and process them with a custom handler. ### Method Not applicable (SDK function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **schema**: The Valibot schema to use for validation. - **input**: The value to validate. - **onError** (optional): A callback function that receives flattened validation issues if the input is invalid. ### Returns An object indicating success or failure, similar to `valibot.safeParse()`. ``` -------------------------------- ### extract(schema).from(input, onError?) Source: https://github.com/gambonny/valext/blob/main/README.md Extracts validated values from an input using a Valibot schema. It returns a result object indicating success or failure, and optionally calls an onError callback with flattened issues if validation fails. ```APIDOC ## extract(schema).from(input, onError?) ### Description Extracts validated values from an input using a Valibot schema. It returns a result object indicating success or failure, and optionally calls an onError callback with flattened issues if validation fails. ### Method Not applicable (SDK function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **schema**: The Valibot schema to use for validation. - **input**: The value to validate and extract. - **onError** (optional): A callback function that receives flattened validation issues if the input is invalid. ### Returns An object with the following structure: ```typescript { success: true; output: T; // The validated and typed output issues: undefined; } ``` or ```typescript { success: false; output: undefined; issues: ValibotFlattenedIssues; // Flattened validation issues } ``` ``` -------------------------------- ### Basic Value Extraction Source: https://github.com/gambonny/valext/blob/main/README.md Extracts a value from an unknown input using a schema and handles validation issues with a callback. ```typescript const result = extract(schema).from(unknownValue, issues => console.warn(issues)) ``` -------------------------------- ### Successful Extraction Result Source: https://github.com/gambonny/valext/blob/main/README.md Represents the structure of a successful value extraction using valext. ```typescript { success: true; output: T; issues: undefined; } ``` -------------------------------- ### Failed Extraction Result Source: https://github.com/gambonny/valext/blob/main/README.md Represents the structure of a failed value extraction using valext, including flattened validation issues. ```typescript { success: false; output: undefined; issues: ValibotFlattenedIssues; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.