1.1.15 • Published 5 years ago
perfectobj v1.1.15
PerfectObj
Get your perfect model with one easy schema or with specific editions on the original object.
Tech
PerfectObj uses open source projects to function properly such as:
- Ramda - A practical functional library for JavaScript programmers.
Installation
Install the dependencies and devDependencies and start the server.
$ npm install perfectobj
Properties
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 |
Examples
These are simple some examples
Original Object
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']
}
Perfect Object
const PerfectObj = require('perfectobj');
const personModel = new PerfectObj(person);
Model Object
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);
OUTPUT
{
props: {
identification: '964328461',
telephone: '+50685886810',
address: { apartment: 'Belén, Heredia', home: 'Golfito, Puntarenas' },
interests: [ 'soccer' ],
fullName: 'Marcus Espinoza',
birthday: '1995/08/01'
}
}
Todos
- Write Tests
- Add changelog
License
MIT