Validator
Home
  • Getting started
  • Basic usage
  • Primitives
    • string
    • number
    • boolean
    • bigint
    • null
    • undefined
  • NON-PRIMITIVES
    • object
    • array
    • record
    • tuple
    • instanceOf
    • enum
    • date
  • Utility
    • optional
    • and
    • or
    • partial
    • required
    • omit
    • pick
    • if
    • cast
    • any
Powered by GitBook
On this page
  • Usage
  • Options
  • Examples

Was this helpful?

Edit on GitHub
  1. Primitives

null

Learn about the available options, methods and use cases.

Usage

Following is the simple usage of this validator

import e from "validator";

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

Options

Following are the available options for this validator

interface INullValidatorOptions
  extends Omit<TBaseValidatorOptions, "cast" | "castOptions"> {
  /** Pass custom messages for the errors */
  messages?: Partial<Record<"typeError", TErrorMessage>>;
}

Examples

Read the examples below to understand different use cases

Case 1 (Basic usage)

// Validate null
await e.null().validate(null) // returns null

Case 2 (Passing options)

// Validate null
await e.null({
    messages: {
        typeError: "Not a null!",
    }
}).validate(1) // throws ValidationException
PreviousbigintNextundefined

Last updated 10 months ago

Was this helpful?