Spec-Zone.ru › Valibot

nanoid

Creates a Nano ID validation action.

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

Generics

  • TInput extends string
  • TMessage extends ErrorMessage<NanoIdIssue<TInput>> | undefined

Parameters

  • message TMessage

Explanation

With nanoid you can validate the formatting of a string. If the input is not an Nano ID, you can use message to customize the error message.

Returns

  • Action NanoIdAction<TInput, TMessage>

Examples

The following examples show how nanoid can be used.

Since Nano IDs are not limited to a fixed length, it is recommended to combine nanoid with length to ensure the correct length.

Nano ID schema

Schema to validate a Nano ID.

const NanoIdSchema = v.pipe(
  v.string(),
  v.nanoid('The Nano ID is badly formatted.'),
  v.length(21, 'The Nano ID must be 21 characters long.')
);

Related

The following APIs can be combined with nanoid.

Schemas

any, string, unknown

Methods

pipe

Utils

isOfKind, isOfType

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

Spec-Zone.ru

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