picklist

Creates a picklist schema.

const Schema = picklist<TOptions>(options, message);

Generics

Parameters

Explanation

With picklist you can validate that the input corresponds to a picklist option. If the input is invalid, you can use message to customize the error message.

picklist works in a similar way to enum_. However, in many cases it is easier to use because you can pass an array of strings instead of an enum.

Returns

Examples

The following examples show how picklist can be used.

Language schema

Schema to validate programming languages.

const LanguageSchema = picklist(['JavaScript', 'TypeScript']);

Country schema

Schema to validate country codes.

const countries = [
  { name: 'Germany', code: 'DE' },
  { name: 'France', code: 'FR' },
  { name: 'United States', code: 'US' },
] as const;

const CountrySchema = picklist(
  countries.map((country) => country.code),
  'Please select your country.'
);

The following APIs can be combined with enum_.

Schemas

Methods

Contributors

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

  • GitHub profile picture of fabian-hiller
  • GitHub profile picture of sqmasep

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 dailydotdev
  • GitHub profile picture of ivan-mihalic
  • GitHub profile picture of KATT
  • GitHub profile picture of osdiab
  • GitHub profile picture of Thanaen
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of caegdeveloper