Ts Json Object Versions Save

JSON object validation for typescript

v0.4.0

1 year ago

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

v0.3.0

1 year ago

This release fixes #4.
Thanks @ste2425 !

v0.2.10

3 years ago

class Nullable extends JSONObject {
    @optional
    value?:string;
}
let n = new Nullable({ "value":null })
// this would result in n.value == "null" (as string)
// this release fixes this bug 

v0.2.9

3 years ago

v0.2.8

4 years ago

This release fixes an issue with inheritance.
In previous versions, the list of keys for a given class was common for all descendants of a given base class, which is of course, plain wrong.

v0.2.7

4 years ago
class DateTest extends JSONObject {
            @required
            date:Date
}
// Works! anything that works with a Date CTOR should work
let test1 = new DateTest({date:1}) 
// Will throw an error! date is invalid
let test2 = new DateTest({date: 'not going to work'})