Spec-Zone.ru › Valibot

toNumber

Creates a to number transformation action.

const Action = v.toNumber<TInput, TMessage>(message);

Generics

  • TInput extends any
  • TMessage extends ErrorMessage<ToNumberIssue<TInput>> | undefined

Parameters

  • message TMessage

Explanation

With toNumber you can transform the input to a number. If the input cannot be transformed, you can use message to customize the error message.

Returns

  • Action ToNumberAction<TInput, TMessage>

Examples

The following examples show how toNumber can be used.

Number schema

Schema to validate a string and transform it to a number.

const NumberSchema = v.pipe(v.string(), v.toNumber());

Related

The following APIs can be combined with toNumber.

Schemas

any, bigint, boolean, custom, date, null, string, unknown

Methods

pipe

Utils

isOfKind, isOfType

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

Spec-Zone.ru

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