This is a simple serializer for serializing data, keeping the type and refs in a certain context
npm i @cat5th/serializer -S
import { Serializer } from '@cat5th/serializer'
import { Unserializer } from '@cat5th/serializer'
const serializer = new Serializer()
class A() {
hello = 'Hello world!'
}
// after serializer, you can stringify data to string and transport it by ajax or sth
JSON.stringify(serializer(new A))
const unserizer = new Unserilazer()
class A() {
hello = 'Hello world!'
}
// get data from string, and unserializer to A instance
unserilazer(JSON.parse(data), { classes: { A } })
serializer will keep the references, you will get same reference as following example
const obj = {}
cons arr = [obj, obj]
serliazer.serialize(array)
const arr = unserializer.unserializer(data)
arr[0] === arr[1] // => true