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

@krishnapawar/kp-validator-helper

v1.0.0

Published

The `kp-validator-helper` is a lightweight JavaScript library designed to simplify data interaction and validation. It streamlines the validation processes and provides essential helper functions to enhance efficiency in your projects.This package provide

Downloads

15

Readme

validator-helper

The validator-helper is a lightweight JavaScript library designed to simplify data interaction and validation. It streamlines the validation processes and provides essential helper functions to enhance efficiency in your projects.

npm i validator-helper

OR

npm i @krishnapawar/validator-helper

Usage

This package provides a lightweight JavaScript library for validating your JavaScript projects. It can be utilized in Node.js projects, as well as Vue.js and React.js projects, by installing it and incorporating a simple middleware.

validator-helper All methods.

const {
    validater,
    isObject,
    isNotObject,
    isNotEmpty,
    isEmpty
} = require("validator-helper");

validater Method:

Simple validation example

    const valid = validater(req,{
        name:"required",
        date:"required",
        email:"required",
        mobile:"required"
    });

  if(valid){
    return res.json(valid);
  }
  //output you get
  {
      "status_code": "400",
      "status": false,
      "message": "mobile is required!"
  }

we can manuplate status_code , status and message as well

For Example

    const valid = validater(req,{
        name:"required",
        date:"required",
        email:"required",
        mobile:"required"
    },{
        statusCode:404,
        status: "error",
        message:{
          name:'User name is required',
          date:'Invalid O black date field',
        }
    });
  //output you get
  {
      "status_code": "404",
      "status": "error",
      "message": "User name is required"
  }

we can gat all error in single array by using errors:true

For Example

    const valid = validater(req,{
        name:"required",
        date:"required",
        email:"required",
        mobile:"required"
    },{
        errors:true,
        message:{
          name:'User name is required',
          date:'Invalid date field',
        }
    });
  //output you get like this
  [
    "User name is required",
    "Invalid date field",
    "email is required!",
    "mobile is required!"
  ]

we can set Minimum and Maximum length by using min:1 and min:10

For Example

    const valid = validater(req,{
        name:"required",
        date:"required",
        email:"required",
        mobile:{
          require:true,
          min:10,
          max:12
        }
    },{
        errors:true,
        message:{
          name:'User name is required',
          date:'Invalid date field',
        }
    });
  //output you get like this
  [
    "User name is required",
    "Invalid date field",
    "email is required!",
    "mobile is required!"
  ]

  //OR
 
  [
    ...
    "Minimum Length 10."
  ]

  //OR

  [
    ...
    "Maximum Length 12."
  ]

we can also manipulate thes message accourding to us like this

For Example

    const valid = validater(req,{
        name:"required",
        date:"required",
        email:"required",
        mobile:{
          require:true,
          min:10,
          max:12
        }
    },{
        errors:true,
        message:{
          name:'User name is required',
          date:'Invalid date field',
          mobile:{
            require:"Mobile NO is required",
            min:"Mobile No Minimum length 10 digit",
            max:"Mobile No Maximum length 12 digit"
          }
        }
    });
  //output you get like this
  [
    "User name is required",
    "Invalid date field",
    "email is required!",
    "Mobile NO is required"
  ]

  //OR
 
  [
    ...
    "obile No Minimum length 10 digit"
  ]

  //OR

  [
    ...
    "Mobile No Maximum length 12 digit"
  ]

More Examples

Email validate

For Example

    const valid = validater(req,{
        description:{
          required:true,
          email:true
        }
    });

Mobile No or Phone validation

For Example

    const valid = validater(req,{
        mobile:{
        phone:true,
      },
    });

Data type validation

For Example

    const valid = validater(req,{
        mobile:{
        phone:true,
        type:"number"
      },
    });

    //OR 
    const valid = validater(req,{
        mobile:{
        phone:true,
        type:"string"
      },
    });

  //like we can use 

Date validation

For Example

    const valid = validater(req,{
        dob:{
          required:true
          date:true
        }
    });

Custome validate by regex

For Example

    const valid = validater(req,{
        description:{
          required:true,
          regex:/^.{25}$/
        }
    });

Features

  • Required Field Validation: Ensure mandatory fields are filled.
  • Email Validation: Verify the correctness of email formats.
  • Phone Number Validation: Validate and format phone numbers.
  • Min/Max Length or Digit Validation: Define minimum and maximum length or digit constraints.
  • Data Type Validation: Check if data types meet specified criteria.
  • Custom Validation with Regex: Create custom validation using regular expressions.
  • Date Validation: Validate dates, ensuring they meet specified criteria (e.g., format, range).
  • Additional Methods:
    • isObject: Check if a variable is an object.
    • isNotObject: Verify if a variable is not an object.
    • isNotEmpty: Confirm that a variable is not empty.
    • isEmpty: Check if a variable is empty.

License

This software is released under the MIT License. MIT

My Social Media Profiles

LinkedIn

GitHub

Instagram

Twitter