Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qiwi/serializer
Utility to serialize/deserialize js object and restore its context as close as possible
https://github.com/qiwi/serializer
Last synced: 4 days ago
JSON representation
Utility to serialize/deserialize js object and restore its context as close as possible
- Host: GitHub
- URL: https://github.com/qiwi/serializer
- Owner: qiwi
- License: mit
- Created: 2020-04-15T10:14:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T06:27:16.000Z (about 1 year ago)
- Last Synced: 2024-07-16T14:21:18.575Z (4 months ago)
- Language: TypeScript
- Size: 6.75 MB
- Stars: 0
- Watchers: 7
- Forks: 1
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @qiwi/serializer
[![Maintainability](https://api.codeclimate.com/v1/badges/7d9ced8d8d9d2ab8fc54/maintainability)](https://codeclimate.com/github/qiwi/serializer/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/7d9ced8d8d9d2ab8fc54/test_coverage)](https://codeclimate.com/github/qiwi/serializer/test_coverage)> Utility to serialize/deserialize js object and restore its context as close as possible
## Motivation
In JS:
* We have no "classpaths", so we cannot bind class ref with its package/module.
* `JSON.serialize`, `v8.serialize` does not produce any meta that could be used to restore object context (proto, bindings).There are just a few JSON supersets that change the situation slightly: [json-schema](https://json-schema.org/), [serialize-javascript](https://github.com/yahoo/serialize-javascript).
Therefore, yet another one incompatible format does not affect anything.## Suggestions
* Serialized data should describe itself by meta (something like as regular file does: header + ext)
* Classes refs may be found by scanning `require.cache` inners or globals## Status
🚧 Work in progress 🚧 / Experimental / Early preview / pre-alpha version / 0.0.0-draft## Install
```shell script
yarn add @qiwi/serializer
```## Usage
```typescript
import {serialize, deserialize} from '@qiwi/serializer'
import {A} from './A'const a: A = new A()
const serialized: string = serialize(a)
const restored: A = deserialize(serialized)console.log(restored instanceof A) // true
```## Refs
* [https://stackoverflow.com/questions/9791925/list-of-currently-loaded-node-js-modules](https://stackoverflow.com/questions/9791925/list-of-currently-loaded-node-js-modules)
* [https://github.com/facebook/jest/issues/5120](https://github.com/facebook/jest/issues/5120)
* [https://github.com/facebook/jest/issues/5741](https://github.com/facebook/jest/issues/5741)## License
[MIT](LICENSE)