Structure
Structure v2
Structure v2
  • Introduction
  • Schema concept
    • Shorthand and complete attribute definition
    • Circular reference
    • Nullable attributes
  • Custom setters and getters
  • Coercion
    • Primitive type coercion
    • Arrays coercion
    • Generic coercion
    • Recursive coercion
    • Disabling coercion
  • Validation
    • String validations
    • Number validations
    • Boolean validations
    • Date validations
    • Array validations
    • Attribute reference
    • Nested validations
    • Validate raw data
  • Strict mode
  • Cloning an instance
  • Serialization
  • Testing
  • Battlecry generators
  • Migrating from v1
  • Support and compatibility
  • Changelog
  • Contributing
  • License
  • GitHub
Powered by GitBook
On this page

Was this helpful?

  1. Validation

Number validations

  • required: can't be undefined (default: false)

  • equal: * equal to passed value

  • integer: must be an integer (default: false)

  • precision: maximum number of decimal places

  • positive: must be positive (default: false)

  • negative: must be negative (default: false)

  • multiple: must be a multiple of the passed value

  • min: ** minimum valid value (works like the >= operator)

  • greater: ** must be greater than passed value (works like the > operator)

  • max: ** maximum valid value (works like the <= operator)

  • less: ** must be smaller than passed value (works like the < operator)

  • nullable: accepts null (default: false)

const Pool = attributes({
  depth: {
    type: Number,
    positive: true
  },
  width: {
    type: Number,
    min: { attr: 'depth' }
  },
  length: {
    type: Number,
    greater: { attr: 'width' }
  },
  capacity: {
    type: Number,
    nullable: true
  }
})(class Pool {
  getVolume() {
    return this.depth * this.width * this.length;
  }
});
PreviousString validationsNextBoolean validations

Last updated 4 years ago

Was this helpful?