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

simple-json-validate

v1.0.5

Published

tool for validate json input

Downloads

38

Readme

SIMPLE-JSON-VALIDATE

tool for check json input and set json data.

NOTE: This still beta version. Feel free to report bug thank!

Getting Started

Installing

npm install simple-json-validate --save

Usage

const validate = require('simple-json-validate');
const pattern = {
    "test": {
        "id": "required|number|max_length[13]|min_length[13]",
        "email": "required|email",
        "period": "default[30]",
        "value": "required|limit[100]"
    }
};
let input = {
    "id": "1111111111111",
    "email": "[email protected]",
    "value": "10000"
}

let validated = new validate(pattern);
let output = validated.check('test', input);
console.log(output);//{"id":"1111111111111","email":"[email protected]","value":"100","period":"30","isValid":true}

How To use

1. Require SIMPLE-JSON-VALIDATE

const validate = require('simple-json-validate');

2. Setup Your Json Pattern

  var pattern = {
    "first pattern name": {
      "json key": "setup format"
    },
    "second pattern name": {
        "json key": "setup format"
    }
  }
  new validate(pattern);

3. Call Check Function

   let output = validated.check("pattern name", input)
    NOTE: input can be only JSON Object

4. Check Your Input Is Valid Or Not

   if(output.isValid){
       //awesome code here
   }

The Format

You can use multiple format with | between format such as

"id": required|number|max_length[13]|min_length[13]

Avaliable Format

required

data is required

number

accept only number

email

accept only email

default[...]

set default data (This option will use only when input data is invalid or null. replace [...] with default data such as default[30])

avaliable[...]

set data that can be accepted (replace [...] with accepted data such as avaliable[banana, weed])

limit[...]

what ever input data will set to limit data (replace [...] with limit data such as limit[100])

max_length[...]

maximum length of data can be accepted (replace [...] with interger such ass max_length[13])

min_length[...]

minimum length of data can be accepted (replace [...] with interger such as min_length[13])

max_value[...]

maximum value of data can be accepted (replace [...] with interger such as man_value[10])

min_value[...]

minimum value of data can be accepted (replace [...] with interger such as min_value[1])

Authors

freeweed

License

This project is licensed under the WTFPL License - see the LICENSE.md file for details

Changelog

[1.0.3]

Fixed

  • some stupid bug

[1.0.2]

Fixed

  • validate number bug

TODO

  • add nested child validate
  • add unit test
  • improve performance
  • add more type