1.2.7 • Published 7 years ago

object-data-validator v1.2.7

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

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)
1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago