1.0.6 • Published 3 years ago

@payiz/validator v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

@payiz/validator

Validation module

How to use

const Validator = require('@payiz/validator');

const Schema = {
    param: {
        type: 'string',
        required: true
    }
};

const error = Validator.validate({ param: 'Hello world' }, Schema);
if (error) {
    console.log(error);
}

Response

Validator.validate return undefined when everything is correct and an array of object when there is at least one error. The object is formatted as below:

const error = {
    code: '',
    field: '',
    value: ''
}

Schema format

const functionSchema = {
    parameter: {
        type: 'string|number|...',
        required: true,
        ...
    }
};

Validation types

Rules

Boolean

  • Required
  • Truthy
  • Falsy

Number

  • Required
  • min
  • max
  • negative
  • positive
  • integer
  • float

String

  • required
  • alpha
  • numeric
  • alphanumeric
  • length
  • min
  • max
  • lowercase
  • uppercase
  • capitalize
  • email WIP
  • password WIP
  • phone WIP
  • domain WIP
  • url WIP
  • only TODO

Object

  • required
  • keys
  • contains WIP

Array

  • required
  • length
  • max
  • min
  • unique
  • contains WIP
  • items TODO

Date

1.0.6

3 years ago

1.0.5

3 years ago

1.0.2

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago