0.1.0 • Published 7 years ago

ian-validator v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

ian-validator

Validates an input document against a schema.

Usage

const document1 = {
  username: 'su'
}

const document2 = {
  name: 'Dawg Man',
  email: 'dawg@man.com',
  username: 'dawg'
}

const schema = {
  name: {
    type: 'string',
    isRequired: true
  },
  email: {
    type: 'string',
    isEmail: true
  },
  username: {
    minChars: 3,
    maxChars: 16
  }
}

ianValidator(document1, schema)
  .then(result => {}) // result is `false`.

ianValidator(document2, schema)
  .then(result => {}) // result is an object similar to `document2`.
                      // (in this case it is a straight copy.)

Schema Spec

const schema = {
  property: {
    type: 'string'|'number'|'regexp'|'object'|'array',
    isEmail: true|false,
    isRequired: true|false,
    minChars: Number, // if type: 'string'
    maxChars: Number, // if type: 'string'
    minValue: Number, // if type: 'number'
    maxValue: Number, // if type: 'number'
    transform: function (value) {}
    check: function (value) {} // custom validation function, must return/resolve boolean.
  }
}

LICENSE: MIT

0.1.0

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago