Added `minLength` and `maxLength`
Long overdue, added minLength and maxLength decorators.
class Person extends JSONObject {
@minLength(5)
@maxLength(10)
name:string
}
let p:Person
p = new Person({
name: 'foo'
}) // will throw an error, too short
p = new Person({
name: '1234567890 too long'
}) // will throw an error, too long
p = new Person({}) // ok, optional by default
p = new Person({'
name:'Dilbert'
}') // ok, length is 7Also works on arrays:
class Person extends JSONObject {
@minLength(1)
@maxLength(3)
traits:string[]
}
let p:Person
p = new Person({
traits: ['kind','strong']
}) // OK, two traits
p = new Person({
traits: ['kind','strong','fast','slow']
}) // will throw an error, too many traits