1.0.2 • Published 3 years ago

prototype-stringify v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

prototype-stringify

stringify simple object, including data in prototypes.

Install

npm install prototype-stringify

Usage

var a = { b: 1, c: { d: 2 }, e: { f: 3 } };
var aa = Object.create(a);

aa.bb = 11;
aa.c.dd = 22;
aa.e = Object.create(a.e);
aa.e.ff = 33;

var s1 = JSON.stringify(aa);		//JSON.stringify() exclude data in prototype
console.log("JSON.stringify():\n\t" + s1);
//{"bb":11,"e":{"ff":33}}

var s2 = prototype_stringify(aa);		//to include data in prototypes
console.log("prototype_stringify():\n\t" + s2);
//{"b":1,"bb":11,"c":{"d":2,"dd":22},"e":{"f":3,"ff":33}}

/*
var expect = {
    b: 1,
    bb: 11,
    c: {
        d: 2,
        dd: 22
    },
    e: {
        f: 3,
        ff: 33
    }
};
*/