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

check-validation

v1.0.6

Published

Downloads

2

Readme

check-validation

- Check validation of Object
- Please let me know issues to my github. if you find bugs :)
- Please let me know some weird text and error message. My english is not good
- Thank you Enjoy!

installing

npm:

npm install check-validation

yarn:

yarn add check-validation

import

import validation from "check-validation" 

var validation = require("check-validation")

Usage

  • Example Data
const data = {
    name: "john",
    email: "[email protected]",
    password: "code123",
    passwordConfirm: "code123",
    gender: "male",
    age: 25,
    hobby: "sports"
}
  • Simple
 let rules = {
     name : "required", // rules for name
     email: "required|email", // rules for email
     age : "number|min[20]|max[30]", // rules for age
     hobby: "required|minLength[2]", // rules for hobby
     password: "required|match[passwordConfirm]", // rules for password
}

const check = validation(data, rules) // {result : true or false , message: error message }

if (check.result) {
    //success
} else {
    //fail
    //console.log(check.message)
}
  • For Custom Error Message

    - if use title inner name object and then change the Subject

    - it must be use with rules

 let rules = {
     name : {
         rules : "required", // rules for name
         title : "my name" // change the key  "name" to "my name" for error message
     }
}
  • Full Custom Error Message

    - if use API names with rules an inner object it will be changing full Error Message

    - Api name works with priority than title

let rules = {
    name: {
        rules: "required", // rules for name
        required: "required error message of name"
    },
    email: {
        rules: "required|email", // rules for email
        title: "email2", // change the key name "email" to "email2" for error message
        email: "email form error message of email" // it does not care title value
    },
    age: {
        rules: "number|min[20]|max[29]", // rules for age
        number: "number error message of age",
        min: "min error message of age",
        max: "max error message of age"
    },
    hobby: {
        rules: "required|minLength[2]", // rules for hobby
        title: "my hobby",
        minLength: "minLength error message of hobby"
    },
    password : {
        rules : "required|match[passwordConfirm]", // rules for password
        title : "code",
        match : "match error message of password"
    }
}
  • For Korean

    - 세번째 파라미터에 ko 스트링을 넣을시에 에러메세지를 한글로 받아 볼 수 있음

    - 타이틀값에 단어만 넣으면 "을/를", "이/가" 는 자동으로 붙음

    - phone api 사용시 한국 휴대전화번호 형식을 체크함

let rules = {
    name: {
        rules: "required", // rules for name
        title : "이름" // 오류 예) 이름을 입력 바랍니다 
    },
    email: {
        rules: "required|email", // rules for email
        title: "나의 이메일", // 오류 예) 나의 이메일이 형식에 맞지 않습니다
    }
} 
const check = validation(data, rules, "ko")

if (check.result) {
    //success
} else {
    //fail
    //console.log(check.message)
}

#API

|name & usage|description| |:----------------|:----------------| |required| check blank, null, undefined| ||| |email| check email format| ||| |number| check number| ||| |phone| check cell phone format (in Korea)| ||| |korean| check Korean| ||| |english| check English| ||| |englishNumber| check English and Number| ||| |match[otherValueInObject]| check match with other value| ||| |min[number]| minimum value | ||| |max[number]| maximum value | ||| |length[number]| lengths of string| ||| |minLength[number]| minimum lengths of string| ||| |maxLength[number]| maximum lengths of string| |||