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

mez-validation

v2.0.2

Published

It is a pure and open source node js library that provides validation method to check from inputs and thier data

Downloads

461

Readme

mez-validation

[![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url] [![Node.js Version][node-version-image]][node-version-url] [![Build Status][github-actions-ci-image]][github-actions-ci-url] [![Test Coverage][coveralls-image]][coveralls-url]

It is a pure and open source node js library that provides validation method to check from inputs and thier data

First lunch

Date: 2024-10-25

Installation

$ npm install --save mez-validaton

How it works?

After install this library yuo just have to select the language wich you want to show messages by it, then you have to call validation method to enter the data

Valid languages

  • EN => english (default)
  • AR => arabic

Ex1:

const age = 10;

Mez.lang("AR") // langauge of messages will shown in arabic

Mez.validation([
    {
        name: "age",
        data: age,
        is: ["required", "number", "less:15"]
    }
])

=> value will return:

{
    messages: [],
    error: false,
    check: [
        { title: 'age', task: 'required', pass: true },
        { title: 'age', task: 'number', pass: true },
        { title: 'age', task: 'less', pass: true },
    ],
    wrongInputs: [],
    status: 200
}

Ex2:

const age = 10;

Mez.validation([
    {
        name: "age",
        data: age,
        is: ["required", "string"] 
    }
])

=> value will return:

{
    messages: ["age must be string"], // default language is "English"
    error: true,
    check: [
        { title: 'age', task: 'required', pass: true },
        { title: 'age', task: 'string', pass: false },
    ],
    wrongInputs: [ "age" ],
    status: 400
}

Note: if is array to any element is empty or null it will take any type which accept anything and that is mean his pass value is true

Messages array

It provides a list of messages to be displayed when validation fails in task related in an input

Error value

If all tasks is passed in check array => error: false, status: 200, if one task or more is not passed in check array => error: true, status: 400

Check array

It will ensure to check on all data and all tasks if passed or no and to handle your messages if you want

WrongInputs array

It will contains a list of variables name which not passed in check array

Status value

  • 200: Success (all tasks are passed in check array)
  • 400: Error (there one task or more is not passed in check array)

How can i use Mez.validation method?

const age = 10;

const validation = Mez.validation([
    {
        name: "age",
        data: age,
        is: ["required", "string"]
    }
])

if(validation.error) {
    conosole.log({state: 'falied', wrongInputs: validation.wrongInputs})
} else {
    conosole.log({state: 'success'})
}

Note: if you not insert a name to the data, it will take an default name which depaned on his index in inputs

Ex:

const validation = Mez.validation([
    {
        data: age, // Default name: Input1 
        is: ["required", "string"]
    }
])

Note: all of these patterns will return synatx error

  • 1
Mez.validation()
  • 2
Mez.validation([
    {
        is: ["required", "string"]
    }
])
  • 3
Mez.validation([
    {
        data: age,
    }
])

Valid Types to check in is array

  • required => data must be required and can not be empty or null
  • string => type of data must be a string
  • number => type of data must be a number
  • boolean => type of data must be a boolean
  • [string] => type of data must be a string array (all elements of array must be string)
  • [number] => type of data must be a number array (all elements of array must be number)
  • [boolean] => type of data must be a boolean array (all elements of array must be boolean)
  • array => type of data must be an array
  • email => data must be have a valid email format
  • url => data must be have a valid email format
  • date => data must be have a valid data format depending on (YYYY-MM-DD)
  • time => data must be have a valid time format depending on (HH:MM:SS)
  • phone => data must be have a valid phone format
  • eq:X => data must be equal X value (X must be selected by the developer)
  • len:X => length of data must be equal X value (X must be selected by the developer)
  • max:X => length of data must be equal or less than X value (X must be selected by the developer)
  • min:X => length of data must be equal or greater than X value (X must be selected by the developer)
  • less:X => data must be less than X value (X must be selected by the developer)
  • more:X => data must be greater thanX value (X must be selected by the developer)
  • less-eq:X => data must be equal or less than X value (X must be selected by the developer)
  • more-eq:X => data must be equal or greater than X value (X must be selected by the developer)
  • not-eq:X => data can not be equal X value (X must be selected by the developer)
  • contains:X => data must be contains X value (X must be selected by the developer)
  • not-contains:X => data can not be contains X value (X must be selected by the developer)
  • in:X => data must be has X value (X must be selected by the developer) Note: this data must be an array to implement the in task
  • not-in:X => data can not be has X value (X must be selected by the developer) Note: this data must be an array to implement the in task

License

MIT