﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head># parseBoolean

> This document is the Markdown version of [valibot.dev/api/parseBoolean/](https://valibot.dev/api/parseBoolean/). For the complete documentation index, see [llms.txt](https://valibot.dev/llms.txt).

Creates a parse boolean transformation action.

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

## Generics

- `TInput` `extends any`
- `TConfig` `extends ParseBooleanConfig | undefined`
- `TMessage` `extends ErrorMessage<ParseBooleanIssue<TInput>> | undefined`

## 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

- `Action` `ParseBooleanAction<TInput, TConfig, TMessage>`

## Examples

The following examples show how `parseBoolean` can be used.

```ts
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'],
    })
  ),
});
```

## Related

The following APIs can be combined with `parseBoolean`.

### Schemas

[`any`](/api/any.md)