Skip to content

Added `minLength` and `maxLength`

Choose a tag to compare

@moshegottlieb moshegottlieb released this 24 Jun 07:36
· 5 commits to master since this release

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 7

Also 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