A simple and lonely serialization library for JS
yarn add deserted
Generated by Typedoc: https://vitoke.github.io/deserted/globals.html
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)
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)
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:
number
, string
, boolean
, undefined
, null
, Symbol
Number
, String
, Boolean
Array
, Map
, Set
Date
Error
Things that require some configuration:
Symbols
, if they need to be reconnected to existing Symbols
Things that are not serializable:
Promises
TBD
Generated using TypeDoc