packer-js
TypeScript icon, indicating that this package has built-in type declarations

3.0.3 • Public • Published

Gitpod Ready-to-Code

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");

Package Sidebar

Install

npm i packer-js

Weekly Downloads

0

Version

3.0.3

License

ISC

Unpacked Size

57.1 kB

Total Files

7

Last publish

Collaborators

  • berhalak