Get your perfect model with one easy schema or with specific editions on the original object.
PerfectObj uses open source projects to function properly such as:
- [Ramda] - A practical functional library for JavaScript programmers.
Install the dependencies and devDependencies and start the server.
$ npm install perfectobj
For the creation of the model we need, perfectObj offers possibilities such as:
Name | Description |
---|---|
rename | Change the name of a key |
assoc | Set a new attribute in model |
type | Define a type for an attribute |
omit | Get undescribed items from a collection |
picks | Get the described items of a collection |
enhacer | Function on one or more attributes of the original object |
These are simple some examples
const person = {
name: 'Marcus Espinoza',
identification: 964328461,
telephone: 85886810,
address: {
apartment: 'Belén, Heredia',
girl: 'San Rafael, Heredia',
home: 'Golfito, Puntarenas'
},
interests: ['videogames', 'soccer', 'technology']
}
const PerfectObj = require('perfectobj');
const personModel = new PerfectObj(person);
personModel
.rename('name', 'fullName')
.assoc('birthday', '1995/08/01')
.type('identification', 'string')
.enhacer('telephone', v => `+506${v}`)
.picks('address', ['apartment', 'home'])
.omit('interests', ['technology', 'videogames']);
console.log(personModel);
{
props: {
identification: '964328461',
telephone: '+50685886810',
address: { apartment: 'Belén, Heredia', home: 'Golfito, Puntarenas' },
interests: [ 'soccer' ],
fullName: 'Marcus Espinoza',
birthday: '1995/08/01'
}
}
- Write Tests
- Add changelog
MIT