getTitle

Returns the title of the schema.

If multiple titles are defined, the last one of the highest level is returned. If no title is defined, undefined is returned.

const title = v.getTitle<TSchema>(schema);

Generics

Parameters

  • schema TSchema

Returns

  • title string | undefined

Examples

The following examples show how getTitle can be used.

Get title of schema

Get the title of a username schema.

const UsernameSchema = v.pipe(
  v.string(),
  v.regex(/^[a-z0-9_-]{4,16}$/iu),
  v.title('Username'),
  v.description(
    'A username must be between 4 and 16 characters long and can only contain letters, numbers, underscores and hyphens.'
  )
);

const title = v.getTitle(UsernameSchema); // 'Username'

Overriding inherited titles

Get the title of a Gmail schema with an overridden title.

const EmailSchema = v.pipe(v.string(), v.email(), v.title('Email'));

const GmailSchema = v.pipe(
  EmailSchema,
  v.endsWith('@gmail.com'),
  v.title('Gmail')
);

const title = v.getTitle(GmailSchema); // 'Gmail'

The following APIs can be combined with getTitle.

Actions

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of @EskiMojo14
  • GitHub profile picture of @fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of @antfu
  • GitHub profile picture of @Thanaen
  • GitHub profile picture of @osdiab
  • GitHub profile picture of @ruiaraujo012
  • GitHub profile picture of @hyunbinseo
  • GitHub profile picture of @F0rce
  • GitHub profile picture of @UniquePixels
  • GitHub profile picture of @jdgamble555
  • GitHub profile picture of @nickytonline
  • GitHub profile picture of @KubaJastrz
  • GitHub profile picture of @andrewmd5
  • GitHub profile picture of @caegdeveloper
  • GitHub profile picture of @dslatkin
  • GitHub profile picture of @BrianCurliss