packer-js
v3.0.3
Published
Javascript object serializer
Downloads
8
Maintainers
Readme
packer
Javascript serialization with prototype marker.
instalation
npm install packer-js
yarn add packer-js
Sample
Also see src/test.ts
import { Packer } from 'packer-js';
class Upper {
data: { text: string };
constructor(text: string) {
this.data = {
text
}
}
public toString() {
return this.data.text.toUpperCase();
}
}
Packer.register(Upper);
const unpacked = Packer.unpack<Upper>(Packer.pack(new Upper("lower")))
if (unpacked.toString() != "LOWER") {
throw new Error("Test failed")
}
const unser = Packer.deserialize<Upper>(Packer.serialize(new Upper("lower")))
if (unser.toString() != "LOWER") {
throw new Error("Test failed")
}
console.log("Test passed");