Options
All
  • Public
  • Public/Protected
  • All
Menu

deserted

deserted

A simple and lonely serialization library for JS

Installation

yarn add deserted

API Documenttation

Generated by Typedoc: https://vitoke.github.io/deserted/globals.html

Usage

Simple

import { deserted } from 'deserted'

const myObject = {
  value: 523,
  nested: {
    text: 'foo',
    bar: false
  },
  date: new Date(1990, 1, 1)
}

const asString = deserted.serialize(myObject)

const backToObject = deserted.deserialize(asString)

const quickCloneObject = deserted.clone(myObject)

Advanced

import { deserted, Converters } from 'deserted'

class Test {
  constructor() {
    this.foo = 1
    this.bar = true
  }
}
const test = new Test()
test.bar = false

const testSerializer = deserted.withConverters(Converters.allProps(Test))

const shared = { value: 123, { nested: test: 'foo' } }

const someObject = [shared, { value: shared }, new Map([1, shared])]

const asString = testSerializer.serialize(someObject)

const backToObject = testSerializer.deserialize(asString)

const quickCloneObject = testSerializer.clone(someObject)

Motivation

Serialization is important in any system dealing with data that should be saved or sent over a wire. It is also useful for deep cloning of objects. In a quick search for a simple to use but powerful library, I could not find anything that matches these requirements.

The deserted library can serialize complex object-graphs with circular references without configuration.

Things that are serializable out of the box:

  • primitives: number, string, boolean, undefined, null, Symbol
  • boxed primitives: Number, String, Boolean
  • collections: Array, Map, Set
  • Date
  • Error

Things that require some configuration:

  • serializing custom classes
  • serializing functions (limited, not the goal of this library)
  • serializing non-global Symbols, if they need to be reconnected to existing Symbols

Things that are not serializable:

  • Promises
  • any classes that have some hidden state

In-depth

TBD

Conclusion

Have fun!

Generated using TypeDoc