New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mrmarshall

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mrmarshall

Easy marshalling library

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

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"
    }

FAQs

Package last updated on 17 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts