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

validate-form-7

v0.2.7

Published

A comprehensive data validation package that helps to minimize the amount of code you will write

Downloads

3

Readme

Validate Form 7 provides a comprehensive data validation that helps minimize the amount of code you’ll write.

Example

import validation from 'validate-form-7';

const data = {
      _id: '5bf56a5fc384b83ef6e11071',
      _idx: '5bf56a5fc384b83ef6e11071',
    };
const config = {
      _id: { rules: 'required', title: 'ID' },
      _idx: { rules: 'required|matches:_id', title: 'IDX' },
    };
const resp = validation(data, config);
To validate a single entity
import { validateEntity } from 'validate-form-7';

const data = '27';
const rules = 'minLength:33|maxLength:100';
const title = 'Marks';
const resp = validation(data, rules, title);

Config Reference

|Attribute|Required|Description|Example| |--- |--- |--- |--- | |rules|Yes|You can set as many validation rules as you need for a given field in rules attribute. Validation rules, as a string list separated by a pipe "|" |rules: 'required|minLength:4'| |title|No|A “human” name for this field, which will be inserted into the error message. For example, if your field is named “user” you might give it a human name of “Username”.|title: 'FIELD NAME'|

Validation Response

errors

Default Value: Empty Object {} errors attribute provides the object of invalid field(s) and each field contains the error message(s).

errorsList

Default Value: Empty Array [] errorsList attribute provides the array of error messages of all invalid field(s).

Example
import validation from 'validate-form-7';

const data = {
      ryan: 'this is ryan',
      markhor: 'this is markhor',
      markus: 'this is markus',
    };
    const config = {
      ryan: { rules: 'required|minLength:4', title: 'Ryan' },
      markhor: { rules: 'required|minLength:40', title: 'Markhor' },
      markus: { rules: 'required|maxLength:4', title: 'Markus' },
    };
    const resp = validation(data, config);
    console.log(resp);
Response
{
  errorsList:
   [
    'The Markhor field must be at least 40 characters in length.',
    'The Markus field cannot exceed 4 characters in length.'
    ],
  errors:
   {
     markhor: [ 'The Markhor field must be at least 40 characters in length.' ],
     markus: [ 'The Markus field cannot exceed 4 characters in length.' ],
   }
}

Rule Reference

The following is a list of all the native rules that are available to use:

|Rule|Parameter|Description|Example| |--- |--- |--- |--- | |required|No|Returns FALSE if the form element is empty.|| |matches|Yes|Returns FALSE if the form element does not match the one in the parameter.|matches:form_item| |differs|Yes|Returns FALSE if the form element does not differ from the one in the parameter.|differs:form_item| |minLength|Yes|Returns FALSE if the form element is shorter than the parameter value.|minLength:3| |maxLength|Yes|Returns FALSE if the form element is longer than the parameter value.|maxLength:12| |exactLength|Yes|Returns FALSE if the form element is not exactly the parameter value.|exactLength:8| |greaterThan|Yes|Returns FALSE if the form element is less than or equal to the parameter value or not numeric.|greaterThan:8| |greaterThanEqualTo|Yes|Returns FALSE if the form element is less than the parameter value, or not numeric.|greaterThanEqualTo:8| |lessThan|Yes|Returns FALSE if the form element is greater than or equal to the parameter value or not numeric.|lessThan:8| |lessThanEqualTo|Yes|Returns FALSE if the form element is greater than the parameter value, or not numeric.|lessThanEqualTo:8| |inList|Yes|Returns FALSE if the form element is not within a predetermined list.|inList:red,blue,green| |alpha|No|Returns FALSE if the form element contains anything other than alphabetical characters.|| |alphaNumeric|No|Returns FALSE if the form element contains anything other than alpha-numeric characters.|| |alphaNumericSpaces|No|Returns FALSE if the form element contains anything other than alpha-numeric characters or spaces. Should be used after trim to avoid spaces at the beginning or end.|| |alphaDash|No|Returns FALSE if the form element contains anything other than alpha-numeric characters, underscores or dashes.|| |numeric|No|Returns FALSE if the form element contains anything other than numeric characters.|| |integer|No|Returns FALSE if the form element contains anything other than an integer.|| |decimal|No|Returns FALSE if the form element contains anything other than a decimal number.|| |validUrl|No|Returns FALSE if the form element does not contain a valid URL.|| |validEmail|No|Returns FALSE if the form element does not contain a valid email address.|| |validIP|Yes|Returns FALSE if the supplied IP address is not valid. Accepts an optional parameter of ‘ipv4’ to specify an IP format.||

Click here to see the examples