0.3.0 • Published 7 years ago

deserializer v0.3.0

Weekly downloads
4
License
ISC
Repository
github
Last release
7 years ago

deserializer

deserializer is a hilariously simple package for instantiating classes. It's will instantiate a given class with a given JSON argument. The JSON argument can be in string form or object form, and will be passed to the constructor as an object.

Usage

npm install deserializer

const deserializer = require('deserializer');

class MyClass {
    constructor ({ foo, bar }) {
        this._foo = foo;
        this._bar = bar;
}

const arg1 = { foo: 'fooProp', bar: 'barProp' };
const obj1 = deserializer(arg1, MyClass);

const arg2 = '{"foo":"fooProp","bar":"barProp"}';
const obj2 = deserializer(arg1, MyClass);