1.0.2 ā€¢ Published 2 years ago

@qiwi/serializer v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@qiwi/serializer

Maintainability 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, 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

yarn add @qiwi/serializer

Usage

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

License

MIT