jv

jj-validator

like laravel style of validator

Showing:

Popularity

Downloads/wk

0

Maintenance

No Maintenance Data Available

Package

Dependencies

0

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

jj-validator

like laravel style of validator

return first invalid param info by default

return Chinese invalid message by default

support custom rules and invalid messages

NPM Version Coverage Status Build Status: Linux

NPM

install:

npm install jj-validator

basic usage:

const V = require('jj-validator')

let params = {
  name: 'jarone',
  age: '18'
}

let schema = {
  mobile: 'required|numberic',
  name : 'max:10|min:1',
  age : 'numberic'
}

let invalidMsg = V(params, schema)

console.log(invalidMsg);

/*
[
  {
    paramName: 'mobile',
    value: undefined,
    invalid: '必须传递mobile'
  }
]
*/

English invalid message usage:

const V = require('jj-validator')

let params = {
  name: 'jarone',
  age: '18'
}

let schema = {
  mobile: 'required|numberic',
  name : 'max:10|min:1',
  age : 'numberic'
}

let invalidMsg = V(params, schema, 'en')

console.log(invalidMsg);

/*
[
  {
    paramName: 'mobile',
    value: undefined,
    invalid: 'mobile is required.'
  }
]
*/

get all invalid params info usage:

const V = require('jj-validator')

let params = {
  name: 'jarone',
  age: '18'
}

let schema = {
  mobile: 'required|numberic',
  name : 'max:5|min:1',
  age : 'numberic'
}

let invalidMsg = V(params, schema, 'en', true)

console.log(invalidMsg);

/*
[
  {
    paramName: 'mobile',
    value: undefined,
    invalid: 'mobile is required.'
  },
  {
    paramName: 'name',
    value: 'jarone',
    invalid: 'name can not gt 5. jarone given.'
  }
]
*/

custom rules and invalid messages

const V = require('jj-validator')

let params = {name: 'luy'}

let schema = {name: 'isJarone'}

let extRules = {isJarone: (val) => val === 'jarone'}

let extInvalidMsg = {
  isJarone: (paramName, val) => `${paramName} is not jarone, ${val} given.`
}

let invalidMsg = V(params, schema, 'en', true, extRules, extInvalidMsg)

console.log(invalidMsg);

/*
[
  {
    paramName: 'name',
    value: 'luy',
    invalid: 'name is not jarone, luy given.'
  }
]
*/

Validation rules:

  1. required

  2. bool

  3. numberic

  4. array

  5. max

  6. min

    MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial