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

express-input-validation

v1.0.10

Published

This package is a express middleware for validating input that is in `header`, `query`, `params`, `body`

Downloads

4

Readme

express-input-validation

npm version

An express.js middleware for input validation.

logo-image

Securing your APIs by validating the inputs.

express-input-validation is simple yet powerful node module that makes your API robust and discard any request with invalid input.

Installation

npm install express-input-validation

OR

yarn add express-input-validation

Features

you can ask express-input-validation to get value from any of these(following list) using from key in rules array,

  • Header (header)
  • Query (query)
  • Body (body)
  • Params (param)

and can pass any custom validation function using validation_function in the rules array. Also you can pass a message in rules for particular rule or it'll be default send a invalid ${key_name} as message.

Example

Following are the example for validating using express-input-validation, here I have included all four type of inputs that most commonly an API can have:

    {
        "from": "query",
        "key": "emailId",
        validation_function: value => value.indexOf("@") > -1,
        "datatype": "number",
        "is_optional": true
    }

In rules array the above one can be one of the objects, here I've showed a custom validation_function without message, this ll return Invalid emailId incase the email id is not found or if it doesn't have an @ in the value string.

Now new rule can be defined as is_optional, where if its declared as optional, only if the field value found then it'll be validated otherwise it'll be ignored.

Datatype-check (optional)

In the rule you can also specify a datatype in datatype key to check for specific datatype of the value. datatypes can be checked below.

Datatype | Description | Alternative key --------------------- | ----------------------------|--------------------- number | checks if its a valid number|num, int, integer string | checks if typeof is string and first character is not a numeric| str float | checks if its a number and has a decimal value| - object | checks if a object| obj alphanumeric | checks if value has atleast one character and number | - only-alpha | checks if value has only alphabets| -

Note

  • key, from are required keys in object in all of the rule you define.
  • a rule without a validation_function is considered to be only required field, i.e., express-input-validation only checks if there is a field in specified from key in the object.
  • Datatype is still experimential.

Roadmap

Raodmap

Next-Release

  • Documentation for Getting Started
  • More DataType checks and datetime checks(minor).
  • Code Optimization.
  • Build passing badge after creating test cases.

License

MIT License