New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

smooth-validator

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smooth-validator

Validator for javascript

latest
Source
npmnpm
Version
4.0.1
Version published
Maintainers
1
Created
Source

Smooth-Validator for Javascript

npm version Bundle Size

Getting Started

Installation

npm install smooth-validator

Usage

Smooth-Validator provides you various types of validation for object.

Code Example for Sign Up validation

Pass rules to be applied on data to the parser and parser will return validator which will validate data for you.

const parser = require("smooth-validator");

//Sample signup validation
var rules = {
  email : 'required|email|min:5|max:100',
  password: 'required|min:6|max:30',
  confirm_password: 'required|same:password'
}
var validator = parser(rules) //parser returns validator, which can be used on data object

var data = {
  email: 'gisueinc@gmail.com',
  password: 'strong',
  confirm_password: 'strong'
}
console.log(validator(data))
//OUTPUT: { message: 'validation passed', errors: [] }

Code Example for Custom Message

Smooth-Validator also supports custom message in error.

const parser = require("smooth-validator");

rules = {
  '*emailTo': ["email"],
  created_at: 'after:tomorrow'
}

var validate = parser(rules, {
  message: {
    'emailTo[].email': ':variable failed :type for :value at index :zero',
    'created_at.after' : ':variable is not after :first_value'
  }
})

data = {
  emailTo: ["gmail.com"],
  created_at: new Date()
}
var res = validate(data);
console.log(res.message)
/* Output: 
{
  message: 'emailTo failed email for gmail.com at index 0',
  errors: [
    {
      key: 'emailTo[]',
      message: 'emailTo failed email for gmail.com at index 0'
    },
    { key: 'created_at', message: 'created_at is not after tomorrow' }
  ]
} */

Documentation 📚

Please go through documentation from more details and examples

Contribution

We would love to get help from you on Github.

Core Team

Keywords

frontend

FAQs

Package last updated on 18 May 2022

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