Releases: trojs/objects
Releases · trojs/objects
Better object creation
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 📦
Merge pull request #64 from hckrnews/feature/validation Add the missing files in the package
Add the object validation
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
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']