Class OptionValidator

Implements a compilation of option definitions.

Constructors

  • Creates an option validator based on a set of option definitions.

    Parameters

    • options: Readonly<Record<string, OpaqueOption>>

      The option definitions

    • config: {
          connectives: Required<Readonly<Partial<Record<ConnectiveWord, string>>>>;
          phrases: Required<Readonly<Partial<Record<ErrorItem, string>>>>;
          styles: Required<MessageStyles>;
      } = defaultConfig

      The validator configuration

      • Readonly connectives: Required<Readonly<Partial<Record<ConnectiveWord, string>>>>

        The connective words.

      • Readonly phrases: Required<Readonly<Partial<Record<ErrorItem, string>>>>

        The message phrases.

      • Readonly styles: Required<MessageStyles>

        The message styles.

    Returns OptionValidator

Properties

config: {
    connectives: Required<Readonly<Partial<Record<ConnectiveWord, string>>>>;
    phrases: Required<Readonly<Partial<Record<ErrorItem, string>>>>;
    styles: Required<MessageStyles>;
} = defaultConfig

The validator configuration

Type declaration

  • Readonly connectives: Required<Readonly<Partial<Record<ConnectiveWord, string>>>>

    The connective words.

  • Readonly phrases: Required<Readonly<Partial<Record<ErrorItem, string>>>>

    The message phrases.

  • Readonly styles: Required<MessageStyles>

    The message styles.

letters: Map<string, string> = ...
names: Map<string, string> = ...
options: Readonly<Record<string, OpaqueOption>>

The option definitions

positional: undefined | OptionInfo

Methods

  • Normalizes the value of an option and checks its validity against any constraint.

    Type Parameters

    • T

      The option value data type

    Parameters

    • option: OpaqueOption

      The option definition

    • name: string

      The option name (as specified on the command-line)

    • value: T

      The option value

    Returns T

    The normalized value

    Throws

    On value not satisfying the specified enums, regex or range constraints