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

ez-check-form

v1.1.12

Published

A tiny module that check your form

Downloads

31

Readme

Check Form

Simple, lighweight and smart.

Check Form is a tiny module that check your form with a few line of code.

Installation

Install the package :

npm i ez-check-form 

import the module :

    --NodeJs require--
CheckForm = require("ez-check-form");
       <!-- Or ---!>
    --ES6 import--
import CheckForm from "ez-check-form";

Usage

Enhance an instance of CheckForm with the object and key value of the form.
Example of form structure :

 let formData = {
        firstName: "",
        lastName: "",
        companyName: "",
        phoneNumber: "",
        address: "",
        city: "",
        country: "",
        postCode: "",
        gender: "",
    }

Note: it can work with any type of key/value.

Store the values of the form into your object and open a new instance of CheckForm.
The constructor should contain the form to check and an array of instruction :

let checkForm  = new CheckForm(formData,instruction[]);

Example of single instruction :

{ key: ["phoneNumber"], perform:["isValidPhoneNumber"] }

Note : The key should correspond to at last one of the key in the form data.
Note 2 : There are a multiple built in function to perform see below.

Its also possible to perform multiple check on multiple key :

//check if isn't empty string and not contains Special chars on 
//last name and first name
{ 
key: ["lastName","firstName"], perform: [['hasSpecialChars', 'isEmptyString'], 'reverse']
}
//Check if all the value on the form are empty
{ key: ["*"], perform: ['isEmptyString'] } 
//Concat instructions 
[
   { key: ["*"], perform: [['hasSpecialChars', 'isEmptyString'], 'reverse']},
   { key: ["phoneNumber"], perform: ["isValidPhoneNumber"] },
   { key: ["postCode"], perform: ["isOnlyNumber"] }
]
//You can also use the checkStrSize() that contains three argument :
{ key: ["lastName"], perform: ['checkStrSize',operator,number] } 

Note : The 'reverse' flag isn't available on checkStrSize function.

Its time to the ✨show✨ :

Enhance the EnhanceCheckData() function and get your Model Error Structure:

checkForm.enhanceCheckData();
console.log(checkForm.isInvalidform) // output: boolean
console.log(checkForm.getModelErrorStructure()); 
/* output : 
{
        firstName: { hasError: boolean, errMsg: string[] },
        lastName: { hasError: boolean, errMsg: string[] },
        companyName: { hasError: boolean, errMsg: string[] },
        phoneNumber: { hasError: boolean, errMsg: string[] },
        address: { hasError: boolean, errMsg: string[] },
        city: { hasError: boolean, errMsg: string[] },
        country:{ hasError: boolean, errMsg: string[] },
        postCode: { hasError: boolean, errMsg: string[] },
        gender: { hasError: boolean, errMsg: string[] },
}
    */ 

Function table

Check available for now : | Check | Description| | ------ | ------ | | isMail | check if the input is a valid mail | | isOnlyNumber | check if the input only contain number | | isExternal | check if the input is an external link | | hasSpecialChars | check if contain special character as *%^": | | isStr | perform check on the type of the input if is Str type | | isInt | same as isStr but for Int type | | isEmptyString | check if the input is an empty string | | containsHeb | check if the input contain hebrew characters | | checkStrSize | check if the input is lesser/greater/equal/different than the number expected|

Features incoming

There only built-in function available for now. I plan to add custom regex check and custom function model/error model.