Spec-Zone.ru › Valibot

transformAsync

Creates a custom transformation action.

const Action = v.transformAsync<TInput, TOutput>(operation);

Generics

  • TInput extends any
  • TOutput extends any

Parameters

  • operation (input: TInput) => Promise<TOutput>

Explanation

transformAsync can be used to freely transform the input. The operation parameter is a function that takes the input and returns the transformed output.

Returns

  • Action TransformActionAsync<TInput, TOutput>

Examples

The following examples show how transformAsync can be used.

Blob to string

Schema that transforms a blob to its string value.

const StringSchema = v.pipeAsync(
  v.blob(),
  v.transformAsync((value) => value.text())
);

Related

The following APIs can be combined with transformAsync.

Schemas

any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, map, nan, never, nonNullable, nonNullish, nonOptional, null, nullable, nullish, number, object, objectWithRest, optional, picklist, promise, record, set, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void

Utils

isOfKind, isOfType

Async

arrayAsync, awaitAsync, customAsync, exactOptionalAsync, intersectAsync, lazyAsync, looseObjectAsync, looseTupleAsync, mapAsync, nonNullableAsync, nonNullishAsync, nonOptionalAsync, nullableAsync, nullishAsync, objectAsync, objectWithRestAsync, optionalAsync, pipeAsync, recordAsync, setAsync, strictObjectAsync, strictTupleAsync, tupleAsync, tupleWithRestAsync, undefinedableAsync, unionAsync, variantAsync

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/transformAsync/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API