record

Learn about the available options, methods and use cases.

Usage

Following is the simple usage of this validator

import e from "validator";

await e.record(
    e.string(), // Pass any validator (Required)
    {} // Optionally pass options
)
.validate({}) // returns {}

Options

Following are the available options for this validator

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

  /**
   * Partialize the underlying validator (makes undefined values in the props acceptable)
   *
   * Use e.partial() instead, if working with typescript
   */
  partial?: boolean;

  /**
   * Converts the underlying validator's props that are partialized/optional to required
   *
   * Use e.required() instead, if working with typescript
   */
  required?: boolean;

  /**
   * Pass a key validator for validating the keys of the record specifically
   */
  key?: BaseValidator<any, any, any>;

  /** Delete any undefined props */
  deletePropertyIfUndefined?: boolean;
}

Examples

Read the examples below to understand different use cases

Case 1 (Basic usage)

Case 3 (With casting)

Last updated

Was this helpful?