object-data-validator

1.2.7 • Public • Published

JS Object Data Validator

Example

  1. Define a model
  const FileModel = {
    id: {
      type: DataTypes.INTEGER,
      nullable: false,
    },
    url: {
      type: DataTypes.STRING,
      nullable: false,
    },
  }
 
  const UserModel = { 
    id: {
      type: DataTypes.INTEGER,
      nullable: false,
    },
    name: {
      type: DataTypes.STRING,
      nullable: false,
    },
    nicknames: {
      type: DataTypes.STRING,
      many: true,
    },
    birthDate: {
      type: DataTypes.DATE,
      dateFormat: 'DD/MM/YYYY',
      nullable: false,
    },
    verified: {
      type: DataTypes.BOOLEAN
    },
    document: {
      type: FileModel
    }
  }
  1. Validate
  const user = {
    id: 1,
    name: 'Carlos',
    birthDate: '15/08/1991',
    verified: false,
    nicknames: ['Perez', 'Sanchez'],
    document: {
      id: 1, 
      url: 'www.google.com'
    },
  }
  const validator = new DataValidator(UserModel, user)
  const errors = validator.call()
  console.log(errors)

Readme

Keywords

none

Package Sidebar

Install

npm i object-data-validator

Weekly Downloads

3

Version

1.2.7

License

MIT

Last publish

Collaborators

  • facuspagnuolo