npm.io
0.3.1 • Published 1 year ago

esm-serialize

Licence
MIT
Version
0.3.1
Deps
0
Size
8 kB
Vulns
0
Weekly
0

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';