boolean

Learn about the available options, methods and use cases.

Usage

Following is the simple usage of this validator

import e from "validator";

await e.boolean(
    {} // Optionally pass options
)
.validate(true) // returns true

// Alternatives
e.true();
e.false();

Options

Following are the available options for this validator

interface IBooleanValidatorOptions extends TBaseValidatorOptions {
  /** Pass custom messages for the errors */
  messages?: Partial<
    Record<"typeError" | "notTrue" | "notFalse", TErrorMessage>
  >;

  /** Validate expected value to be true or false */
  expected?: boolean;
}

Examples

Read the examples below to understand different use cases

Case 1 (Using validator options)

Case 2 (Alternative methods)

Last updated

Was this helpful?