0.2.0 • Published 6 years ago

simple-object-validator v0.2.0

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

Simple object validator

Example of usage:

var res = Validator({
   name: {
       type: 'string',
       length: {
           min: 3,
           max: 30
       }
   },
   age: {
       type: 'number',
       minValue: 5,
       maxValue: 150
   },
   gender: {
       type: 'string',
       optional: true,
       defaultValue: 'man'
   },
   married: {
       type: 'boolean',
       optional: true,
       defaultValue: false
   }
}, {
   name: 'Yuriy',
   age: 17,
   married: true
});

Allowed types:

  • boolean
  • number
  • string
  • object
  • array
  • date
  • any

List of params

  • type (can be multiple: string|number)
  • optional
  • test (regexp for string)
  • minLength (for string)
  • maxLength (for string)
  • defaultValue (with optional)
  • minValue (for number)
  • maxValue (for number)
  • allowedValues (array of allowed values)

Success response:

{ status: 'success', value: { name: 'Yura', age: 17, gender: 'man', married: true } }

Error response:

{ status: 'error', errors: [{key: 'name', message: 'wrong type'}] }

Schema error response:

{ status: 'schemaError', message: 'Default value is uses only in optional field' }
0.2.0

6 years ago

0.1.0

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago