Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/berhalak/packer
Serialize javascript
https://github.com/berhalak/packer
database oop serialization
Last synced: 2 months ago
JSON representation
Serialize javascript
- Host: GitHub
- URL: https://github.com/berhalak/packer
- Owner: berhalak
- License: gpl-3.0
- Created: 2019-08-10T23:04:29.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-31T15:27:32.000Z (5 months ago)
- Last Synced: 2024-11-11T14:09:28.350Z (2 months ago)
- Topics: database, oop, serialization
- Language: TypeScript
- Homepage:
- Size: 1.61 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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");
```