Skip to content

Add the object validation

Compare
Choose a tag to compare
@w3nl w3nl released this 05 Mar 16:39
· 391 commits to master since this release
18f77b3

Example usage:

const addressSchema = {
    street: String,
    number: Number,
    postalCode: String,
    city: String,
    country: String,
};

const Address = Obj({ schema: addressSchema })

const myAddress = new Address({
    street: 'Abc',
    number: 42,
    postalCode: '1234AB',
    city: 'Example',
    country: 'The Netherlands'
})

Example usage without a schema:
...

const ObjectWithoutSchema = Obj()
const flatter = new ObjectWithoutSchema({
    a: 1,
    b: 2,
    c: [3, 4],
    d: { e: 5, f: 6 },
    g: { h: { i: 7 } }
})