tk-serializer
About
This library offers a generic serialization system for Javascript.
Deep objects state may be serialized to a string, and reconstructed back.
Class instances are reconstructed properly, as long as they are in the provided namespace. Circular references are handled.
Be warned that resulting serialized value may be quite large.
Typescript definitions are included.
Issues can be reported on GitLab.
Install
Import in node:
npm install tk-serializer
;
Import in browser:
const Serializer = tkSerializerSerializer;
Use
Suppose you have 2 classes Class1 and Class2, whose instances you want to serialize:
const namespace = Class1 Class2;const obj = a: 1 "a" b: "x" c: ; let serializer = namespace; // Optionally, some class instances may be ignored (they will be replaced by *undefined*)serializer; // Serialize the object to a stringlet state = serializer; // Reconstruct the object back (*c* will be undefined)let nobj = serializer;