Options
All
  • Public
  • Public/Protected
  • All
Menu

@ntix/validating

Index

Type aliases

IValidate<TValue>: (value: TValue) => ValidationErrors<TValue>

Type parameters

  • TValue

Type declaration

IValidateAsync<TValue>: (value: TValue) => Promise<ValidationErrors<TValue>>

Type parameters

  • TValue

Type declaration

ValidationErrors<TValue>: TValue extends boolean ? IStandardAnyErrors : TValue extends number ? IStandardNumberErrors : TValue extends string ? IStandardStringErrors : { [ P in { [ K in keyof TValue]: TValue[K] extends () => void ? never : K }[keyof TValue]]?: ValidationErrors<TValue[P]> }

errors returned from validating TValue

Type parameters

  • TValue

Variables

StandardErrors: Readonly<{ EMPTY: any; not: IStandardErrorProviders; null: IErrors; number: IErrors; string: IErrors; equal: any; includes: any; matches: any; max: any; maxLength: any; min: any; minLength: any }> = ...

StandardErrors available

including EMPTY and negated errors

negated error keys are prefixed by 'not' e.g. { notNull: true }

validate: Validator = ...

Functions

  • capitalize(value: string): string
  • createError(not: boolean, errorKey: string, errorValue?: any): IErrors
  • Creates a frozen error object

    Parameters

    • not: boolean

      when set will prefix the capitalised error key with 'not'

    • errorKey: string

      key value for an error e.g. { someKey: true }

    • errorValue: any = true

      value associated with the key e.g. { key: 'some value' }

    Returns IErrors

    a frozen error object

  • hasErrors(errors: IErrors, path?: string): boolean
  • Checks an error object for errors optionally on a given path

    normalises the errors object first

    Parameters

    • errors: IErrors
    • Optional path: string

    Returns boolean

  • isDate(value: any): boolean
  • isEmpty(a: any): boolean
  • isEqual(a: any, b: any): boolean
  • isNumber(a: any): boolean
  • checks values is a number or a string which can be parsed into a number

    Parameters

    • a: any

    Returns boolean

  • isString(value: any): boolean
  • normalize(errors: any): IErrors | any
  • normalizeErrors(errors: any): IErrors | any
  • normalize a validation result, by removing empty sub-properties

    Parameters

    • errors: any

      any result from a validation function

    Returns IErrors | any

    the result with empty sub-properties removed

Generated using TypeDoc