Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-fluent-validation

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-fluent-validation

[![npm](https://img.shields.io/npm/v/koa-fluent-validation.svg?style=for-the-badge)](https://npmjs.com/package/koa-fluent-validation) [![Travis (.org)](https://img.shields.io/travis/technicallyjosh/koa-fluent-validation.svg?style=for-the-badge)](https://t

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-54.55%
Maintainers
1
Weekly downloads
 
Created
Source

koa-fluent-validation

npm Travis (.org) David

Fluent, functional, and extendable validation for Koa 2 body, params, and query. Built on validator for base validations and filters.

Installation

$ npm i koa-fluent-validation

Requirements

  • NodeJS >= 7.6
  • For validating parameters, koa-router's implementation is used with ctx.params.

Usage

Simple App Example

const Koa = require('koa');
const bodyparser = require('koa-bodyparser');
const { validation, v, f } = require('koa-fluent-validation');

const app = new Koa();

app.use(bodyparser());
app.use(validation());

app.use(async (ctx, next) => {
  try {
    await next();
  } catch (e) {
    if (e.status === 422) {
      ctx.body = ctx.validationErrors;
      return;
    }

    // ... some other handling here etc
  }
});

// simple post route
app.use(async (ctx, next) => {
  if (ctx.method !== 'POST') {
    ctx.throw(404);
    return;
  }

  ctx.validateBody(
    {
      firstName: v()
        .required()
        .string(),
      lastName: v()
        .required()
        .string(),
    },
    {
      firstName: f().trim(),
      lastName: f().trim(),
    },
  );

  // your code here
});

app.listen(8080);

Documentation

For documentation see the wiki!

TODO

  • [] Filter Tests

FAQs

Package last updated on 27 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc