1.0.4 • Published 6 years ago

mrmarshall v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

MrMarshall

This is a module for transforming JSON data coming from API into precisely typed object. the use of input object typing functionnalities is optionnal.

Example

A unix timestamp from number to Date JS object

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.

    {
        timestamp: 2018-07-09T14:53:09.792Z,
        username: "lewiscarol"
    }
1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago