Neutered Puppy Masquerade
Introducing npm Teams! Private packages + team management tools.Learn more »

super-ajv

1.1.6 • Public • Published

Super AJV

AJV validator with super powers! See also the AJV full documentation.

Contents

Custom Types

You can set the types you want!

const ajv = new Ajv()
 
ajv.addType('mongoid', {
  compile: function () {
    return function (data) {
      const re = /^(?=[a-f\d]{24}$)(\d+[a-f]|[a-f]+\d)/i
      return re.test(data)
    }
  }
})
 
const schema = {
  properties: {
    user_id: { type: 'mongoid' }
  }
}

Required properties

You can set required property in line:

const schema = {
  properties: {
    user_id: { type: 'mongoid', required: true }
  }
}

And can also set a required property using the '*':

const schema = {
  properties: {
    '*user_id': { type: 'mongoid' }
  }
}

Simplifyed types

const schema = {
  properties: {
    '*name': 'string',
    '*email': 'email',
    'age': 'number',
    '*message': 'string',
  }
}

Test

node test/

License

GNU

"Simplicity is the ultimate sophistication"
Da Vinci

Install

npm i super-ajv

DownloadsWeekly Downloads

51

Version

1.1.6

License

GNU

Unpacked Size

41.1 kB

Total Files

5

Last publish

Collaborators

  • avatar