getMetadata

Returns the metadata of the schema.

If multiple metadata are defined, it shallowly merges them using depth-first search. If no metadata is defined, an empty object is returned.

const metadata = v.getMetadata<TSchema>(schema);

Generics

Parameters

  • schema TSchema

Returns

Examples

The following examples show how getMetadata can be used.

Get metadata of schema

Get the metadata of a username schema.

const UsernameSchema = v.pipe(
  v.string(),
  v.regex(/^[a-z0-9_-]{4,16}$/iu),
  v.title('Username'),
  v.metadata({
    length: { min: 4, max: 16 },
    chars: ['letters', 'numbers', 'underscores', 'hyphens'],
  })
);

const metadata = v.getMetadata(UsernameSchema);

The following APIs can be combined with getMetadata.

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