Spec-Zone.ru › Valibot

mapItems

Создаёт действие преобразования элементов массива.

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

Обобщения

  • TInput extends ArrayInput
  • TOutput extends any

Параметры

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

Пояснение

С помощью mapItems можно применить operation к каждому элементу массива, чтобы преобразовать его.

Возвращаемое значение

  • Action MapItemsAction<TInput, TOutput>

Примеры

В следующих примерах показано, как можно использовать mapItems.

Пометка дубликатов

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

Связанные материалы

Следующие API можно использовать вместе с mapItems.

Схемы

any, array, custom, instance, tuple, unknown

Методы

pipe

Утилиты

isOfKind, isOfType

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

Spec-Zone.ru

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