Releases: moshegottlieb/ts-json-object
Releases · moshegottlieb/ts-json-object
Reflect metadata package update
Update reflect-metadata (the only dependency) to the latest version
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 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
Fix #4 - @array validation does not work on empty objects
Fixed wrong null explicit assignment
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
Merge branch 'master' of github.com:moshegottlieb/ts-json-object
Inheritance issue fixes
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.
Better date validation
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'})