Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/berhalak/packer

Serialize javascript
https://github.com/berhalak/packer

database oop serialization

Last synced: 2 months ago
JSON representation

Serialize javascript

Awesome Lists containing this project

README

        

[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/berhalak/packer)

### packer

Javascript serialization with prototype marker.

###### instalation

``
npm install packer-js
``
``
yarn add packer-js
``

#### Sample

Also see src/test.ts

```javascript
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(Packer.pack(new Upper("lower")))

if (unpacked.toString() != "LOWER") {
throw new Error("Test failed")
}

const unser = Packer.deserialize(Packer.serialize(new Upper("lower")))

if (unser.toString() != "LOWER") {
throw new Error("Test failed")
}

console.log("Test passed");
```