parseBoolean

Creates a parse boolean transformation action.

const Action = v.parseBoolean<TInput, TConfig, TMessage>(config, message);

Generics

Parameters

  • config TConfig
  • message TMessage

Explanation

With parseBoolean you can parse certain "boolish" values into a plain boolean value (e.g. parsing environment variables). It supports both string and non-string values and the comparison is case-insensitive for strings.

By default, the truthy values are true, 1, "true", "1", "yes", "y", "on", and "enabled". The falsy values are false, 0, "false", "0", "no", "n", "off", and "disabled". You can override these defaults via the config argument.

Returns

Examples

The following examples show how parseBoolean can be used.

const EnvSchema = v.object({
  // Default behavior
  PROD_MODE: v.pipe(v.string(), v.parseBoolean()),

  // With custom config
  LOG_MODE: v.pipe(
    v.string(),
    v.parseBoolean({
      truthy: ['verbose', 'chatty', 'record'],
      falsy: ['silent', 'quiet', 'mute'],
    })
  ),
});

The following APIs can be combined with parseBoolean.

Schemas

Methods

Utils

Contributors

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

  • GitHub profile picture of @alexilyaev
  • 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 @UpwayShop
  • GitHub profile picture of @vasilii-kovalev
  • GitHub profile picture of @saturnonearth
  • GitHub profile picture of @ruiaraujo012
  • GitHub profile picture of @hyunbinseo
  • GitHub profile picture of @nickytonline
  • GitHub profile picture of @KubaJastrz
  • GitHub profile picture of @kibertoad
  • GitHub profile picture of @Thanaen
  • GitHub profile picture of @caegdeveloper
  • GitHub profile picture of @bmoyroud
  • GitHub profile picture of @dslatkin