O-Mapper
What
Validation and conversion of a given object to another.
Like this:
to this:
"full_name": "Toby Flenderson" "job": "HR" "birth_date": "1971-04-01" "orders":
How
const omapper = ; const schema = ... ;const input = ... ; const result = ;
Schema
Schemas are objects that will dictate what the final object will contain and where to get the values from the source object. Each key from the schema represents a key of the final object.
const schema = // key property specifies what key to look for in the source object job: key: 'job_name' // when multiple keys are selected, an handler is required to process the multiple values full_name: key: 'fist_name' 'last_name' ` ` // handlers can also be used for single values // the key property can be omitted if it matches the final object // a property can be set as required birth_date: bd required: true // dot notation can also be used // default values can be set in case property doesn't exist orders: key: 'data.orders' default: ;
License
MIT