npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cheke

v1.0.5

Published

Express request validator with object's style response body and inspired by Laravel's Validator

Downloads

19

Readme

Cheke


npm version Build Status Coverage Status Maintainability Known Vulnerabilities

Express request validator with object's style response body and inspired by Laravel's Validator

How to install

  yarn add cheke
  or
  npm install --save cheke

How to use

Rules

  1. Array: array
  2. Boolean: boolean
  3. Date: date
  4. Email: email
  5. Integer: integer
  6. Maximum: max:maximumNumber
  7. Minimum: min:minimumNumber
  8. Number: number, number|min:200, number|max:200
  9. Regular Expression: regx:^[a-z]{6,}
  10. Required: required
  11. String: string, string|min:200, string|max:200
  12. UUID: uuid
  13. Object: object

Types of validation

  • query -> GET /validate-query?page=pageNumber
     app.get('/validate-query', cheke({
       query: {
         pageNumber: 'required|number|min:1',
       }
     }),(req, res) => {
       return res.send({ message: 'Validated' });
     });
     app.get('/validate-query', cheke({
       query: {
         pageNumber: { label: 'Page', type: 'required|number|min:1' },
       }
     }),(req, res) => {
       return res.send({ message: 'Validated' });
     });
  • params -> GET /validate-params/:id
     app.get('/validate-params/:id', cheke({
       params: {
         id: 'required|uuid'
       }
     }),(req, res) => {
       return res.send({ message: 'Validated' });
     });
     app.get('/validate-params/:id', cheke({
       params: {
         id: { label: 'ID', type: 'required|uuid' }
       }
     }),(req, res) => {
       return res.send({ message: 'Validated' });
     });
  • body -> POST /validate-body
     app.post('/validate-body', cheke({
       body: {
         username: 'required|string|min:6',
         password: 'required|string|min:6'
       }
     }),(req, res) => {
       return res.send({ message: 'Validated' });
     });
     app.post('/validate-body', cheke({
       body: {
         username: { label: 'Username', type: 'required|string|min:6' },
         password: { label: 'Password', type: 'required|string|min:6' }
       }
     }),(req, res) => {
       return res.send({ message: 'Validated' });
     });

Example GET /validate?page=4

  const express = require('express');
  const cheke = require('cheke);

  const app = express();
  const { PORT = 3000 } = process.env

  app.use(express.json())
  app.use(express.urlencoded({ extended: false }))

  app.get('/validate', cheke({
    query: {
      page: 'required|number'
    }
  }),(req, res) => {
    return res.send({ message: 'Validated' });
  });

  app.use((req, res, next) => {
    const err = new Error('Not Found');
    err.status = 404;
    next(err);
  });

  app.use((err, req, res) => {
    res.status(err.status || 500).json({
      errors: {
        message: err.message,
        error: err
      }
    });
  });

  app.listen(PORT, () => console.log(`Server listen on port ${PORT}...`));

Issues

Should it happen that the tool broke down on you please head to our Issue tracker

  1. Search if the issue is already discussed or explained.
  2. If no luck feel free to open a new issue and we will get back to you as soon as possible.

Acknowledgments