Skip to content

Releases: trojs/objects

Better object creation

09 Mar 08:49
1a26c3b
Compare
Choose a tag to compare
const addressSchema = {
    street: String,
    number: Number,
    postalCode: String,
    city: String,
    country: String,
};

const Address = Obj({ schema: addressSchema })

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

Now it returns an object, and you can call all methods on the object.
e.g.

myAddress.street // 'Abc'
myAddress.keys() // ['street', 'number', 'postalcode', 'city', 'country']

Add missing files to the package 📦

05 Mar 17:27
c4b05b9
Compare
Choose a tag to compare
Merge pull request #64 from hckrnews/feature/validation

Add the missing files in the package

Add the object validation

05 Mar 16:39
18f77b3
Compare
Choose a tag to compare

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 } }
})

Add the getKeys method

09 Feb 15:37
64f3a1e
Compare
Choose a tag to compare

Removed node 10 support
Fix the getByKey method for array's
If a key if found in the original object, just return the original value.

original:

{
    a: ['Donatello', 'Michelangelo', 'Raphael', 'Leonardo']
}

before the fix getByKey('a') returns:

{
    0: 'Donatello',
    1: 'Michelangelo',
    2: 'Raphael',
    3: 'Leonardo',
}

now getByKey('a') just returns:

['Donatello', 'Michelangelo', 'Raphael', 'Leonardo']