Easy marshalling library
npm install mrmarshall``javascript
import {transform, types} from "MrMarshall";
types.declare("user", {
timestamp: types.number,
username: types.string,
email: types.string
});
transform(
//incoming data from network
{
timestamp: 1531147989792,
username: "lewiscarol",
email: "lewiscarol@domain.tld"
},
//transformations & mapping rules
{
timestamp: (numberValue) => new Date(numberValue),
username: (username) => username
},
//type name is optionnal and check types of the input object
"user"
);
`
This code will output a usable Date object into timestamp property, the username property as is and will throw email property.
`javascript``
{
timestamp: 2018-07-09T14:53:09.792Z,
username: "lewiscarol"
}