Function createValidator

  • Creates a new basic validator.

    For a deep validator which has sub-fields, use createDeepValidator.

    Type Parameters

    • Output
    • Input = unknown

    Parameters

    • expectationMessage: string

      The message to use to describe what is expected. This will be used in the error message template.

    • isValid: ((input: Input) => boolean)

      Returns true if the given input is valid.

        • (input): boolean
        • Parameters

          Returns boolean

    • inputStringify: ((input: Input) => string) = ...

      Stringifies the input for use as the actual {1} token in the validation expectation template. Default is stringifyForPrint with a 500 character max length.

        • (input): string
        • Parameters

          Returns string

    Returns Validator<Output, Input>