Options
All
  • Public
  • Public/Protected
  • All
Menu

koa-req-validation

Index

Type aliases

CustomErrorMessageFunction: (ctx: RouterContext, input: string) => string

Type declaration

    • (ctx: RouterContext, input: string): string
    • Custom validation error message function. This function will receive the request context and the user's input for the parameter, and it has to return the error message as a result.f

      Parameters

      • ctx: RouterContext
      • input: string

      Returns string

CustomValidatorFunction: (input: unknown) => Promise<void>

Type declaration

    • (input: unknown): Promise<void>
    • Definition of custom validation function. Custom validation function should throw an error when ever validation fails.

      Parameters

      • input: unknown

      Returns Promise<void>

CustomValidatorFunctionWithContext: (input: unknown, ctx: RouterContext) => Promise<void>

Type declaration

    • (input: unknown, ctx: RouterContext): Promise<void>
    • Custom validation function with context object.

      Parameters

      • input: unknown
      • ctx: RouterContext

      Returns Promise<void>

SanitationFunctionName: "blacklist" | "escape" | "unescape" | "ltrim" | "normalizeEmail" | "rtrim" | "stripLow" | "toBoolean" | "toDate" | "toFloat" | "toInt" | "trim" | "whitelist"

Allowed sanitation functions by validator.

ValidatorFunctionName: "custom" | "contains" | "equals" | "isAfter" | "isAlpha" | "isAlphanumeric" | "isAscii" | "isBase64" | "isBefore" | "isBoolean" | "isByteLength" | "isCreditCard" | "isCurrency" | "isDataURI" | "isMagnetURI" | "isDecimal" | "isDivisibleBy" | "isEmail" | "isEmpty" | "isFQDN" | "isFloat" | "isFullWidth" | "isHalfWidth" | "isHash" | "isHexColor" | "isHexadecimal" | "isIdentityCard" | "isIP" | "isIPRange" | "isISBN" | "isISSN" | "isISIN" | "isISO8601" | "isRFC3339" | "isISO31661Alpha2" | "isISO31661Alpha3" | "isISRC" | "isIn" | "isInt" | "isJSON" | "isJWT" | "isLatLong" | "isLength" | "isLowercase" | "isMACAddress" | "isMD5" | "isMimeType" | "isMobilePhone" | "isMongoId" | "isMultibyte" | "isNumeric" | "isPort" | "isPostalCode" | "isSurrogatePair" | "isURL" | "isUUID" | "isUppercase" | "isVariableWidth" | "isWhitelisted" | "matches"

Allowed validation function name. This is the available list of validators in the validator.js -module.

Functions

  • Validate request body.

    Parameters

    • bodyParam: string

      The parameter to be validated from request.

      router.post(
      '/auth/login',
      body('username').equals('user').build(),
      body('password').equals('pass').build(),
      handler
      );

    Returns ValidationChain.default

  • Validate request param.

    Parameters

    • routeParam: string

      The parameter to be validated from request.

      router.get(
      '/api/users/:id',
      param('id').isInt().build(),
      handler
      );

    Returns ValidationChain.default

  • Validate request query.

    Parameters

    • queryString: string

      The parameter to be validated from request.

      router.get(
      '/api/tags',
      query('search').contains('_').build(),
      handler
      );

    Returns ValidationChain.default

  • Get validation results out of the context.

    example

    // In request controller const errors = validationResults(ctx); if (errors.hasErrors()) { throw new RequestError(422, errors.mapped()); }

    Parameters

    • ctx: RouterContext<DefaultState, DefaultContext>

      The request context

    Returns ValidationResult.default

Generated using TypeDoc