Serializer of Javascript data, with objects reconstruction
Find a file
2018-12-30 18:31:35 +01:00
src Initial extract 2018-12-30 23:22:16 +01:00
.gitignore Initial extract 2018-12-30 23:22:16 +01:00
.travis.yml Added travis config 2018-12-30 18:28:54 +01:00
activate_node Initial extract 2018-12-30 23:22:16 +01:00
jest.config.js Initial extract 2018-12-30 23:22:16 +01:00
package-lock.json Initial extract 2018-12-30 23:22:16 +01:00
package.json Updated repo url 2018-12-30 18:19:20 +01:00
README.md Added travis badge 2018-12-30 18:31:35 +01:00
tsconfig.json Initial extract 2018-12-30 23:22:16 +01:00

tk-serializer

Build Status

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.

Usage example

import { Serializer } from "ts-serializer";

const namespace = {
    Class1,
    Class2
};
const obj = {
    a: [1, "a", new Class1()],
    b: new Class2("x"),
    c: new Class3()
};

let serializer = new Serializer(namespace);

// Optionally, some class instances may be ignored (they will be replaced by *undefined*)
serializer.addIgnoredClass("Class3");

// Serialize the object to a string
let state: string = serializer.serialize(obj);

// Reconstruct the object back (*c* will be undefined)
let nobj = serializer.unserialize(state);