# @qiwi/serializer

> Utility to serialize/deserialize js object and restore its context as close as possible

Latest version **1.0.2** (published 2022-07-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @qiwi/serializer
pnpm add @qiwi/serializer
yarn add @qiwi/serializer
bun add @qiwi/serializer
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-07-21 |
| First published | 2022-07-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 39.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Anton Golub |
| Maintainers | antongolub, qiwibot, pismenskiy |
| Keywords | serialize, serializer, mock, spy |

## Links

- npm: https://www.npmjs.com/package/@qiwi/serializer
- Repository: https://github.com/qiwi/serialize
- Homepage: https://github.com/qiwi/serialize#readme
- Issues: https://github.com/qiwi/serialize/issues
- npm.io page: https://npm.io/package/@qiwi/serializer

## Dependencies (7)

- [tslib](https://npm.io/package/tslib.md) ^2.4.0
- [nanoid](https://npm.io/package/nanoid.md) ^3.1.9
- [read-pkg-up](https://npm.io/package/read-pkg-up.md) ^7.0.1
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.182
- [@types/nanoid](https://npm.io/package/@types/nanoid.md) ^2.1.0
- [@qiwi/substrate](https://npm.io/package/@qiwi/substrate.md) ^1.20.14
- [builtin-modules](https://npm.io/package/builtin-modules.md) ^3.3.0

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [gbflowengine](https://npm.io/package/gbflowengine.md) — 0 weekly downloads
- [fake-user-data-plugin-flow-requests](https://npm.io/package/fake-user-data-plugin-flow-requests.md) — 0 weekly downloads
- [@wylan24/mockgen](https://npm.io/package/@wylan24/mockgen.md) — 0 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2022-07-21

## 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)

---
_Source: https://npm.io/package/@qiwi/serializer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
