includes
Создает действие проверки includes.
const Action = v.includes<TInput, TRequirement, TMessage>(requirement, message);
Обобщения
TInputextends ContentInputTRequirementextends ContentRequirement<ContentInput>TMessageextends ErrorMessage<IncludesIssue<TInput, TRequirement>> | undefined
Параметры
requirementTRequirementmessageTMessage
Объяснение
С помощью includes можно проверить содержимое строки или массива. Если входные данные не соответствуют requirement, можно использовать message для настройки сообщения об ошибке.
Возвращаемое значение
ActionIncludesAction<TInput, TRequirement, TMessage>
Примеры
В следующих примерах показано, как можно использовать includes.
Строковая схема
Схема для проверки того, что строка содержит определенную подстроку.
const StringSchema = v.pipe(
v.string(),
v.includes('foo', 'The string must contain "foo".')
);
Схема массива
Схема для проверки того, что массив содержит определенную строку.
const ArraySchema = v.pipe(
v.array(v.string()),
v.includes('foo', 'The array must contain "foo".')
);
Связанные материалы
Следующие API можно комбинировать с includes.
Схемы
any, array, custom, instance, string, tuple, unknown
Методы
Утилиты
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/includes/