0.3.1 • Published 11 months ago
esm-serialize v0.3.1
esm-serialize
Serialize a object including it's function into a JSON with Typescript.
Install
npm install esm-serialize
Usage
import parser from 'esm-serialize';
Serialize an object including it's function:
const obj = {
name: 'Bob',
say: function() {
return 'hi ' + this.name;
}
};
const objS = parser.serialize(obj);
typeof objS === 'string';
parser.unserialize(objS).say() === 'hi Bob';
Serialize an object with a sub object:
const objWithSubObj = {
obj: {
name: 'Jeff',
say: function() {
return 'hi ' + this.name;
}
}
};
const objWithSubObjS = parser.serialize(objWithSubObj);
typeof objWithSubObjS === 'string';
parser.unserialize(objWithSubObjS).obj.say() === 'hi Jeff';