Spec-Zone.ru › Valibot

mapItems

Creates a map items transformation action.

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

Generics

  • TInput extends ArrayInput
  • TOutput extends any

Parameters

  • operation (item: TInput[number], index: number, array: TInput) => TOutput

Explanation

With mapItems you can apply an operation to each item in an array to transform it.

Returns

  • Action MapItemsAction<TInput, TOutput>

Examples

The following examples show how mapItems can be used.

Mark duplicates

const MarkedArraySchema = v.pipe(
  v.array(v.string()),
  v.mapItems((item, index, array) => {
    const isDuplicate = array.indexOf(item) !== index;
    return { item, isDuplicate };
  })
);

Related

The following APIs can be combined with mapItems.

Schemas

any, array, custom, instance, tuple, unknown

Methods

pipe

Utils

isOfKind, isOfType

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

Spec-Zone.ru

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