toNumber
Creates a to number transformation action.
const Action = v.toNumber<TInput, TMessage>(message);
Generics
TInputextends anyTMessageextends ErrorMessage<ToNumberIssue<TInput>> | undefined
Parameters
messageTMessage
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
ActionToNumberAction<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
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/toNumber/