deserializer
v0.3.0
Published
Deserializes JSON to a given class.
Downloads
23
Readme
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);