superjson
superjson copied to clipboard
Add Symbol Support
This would add support for Symbols for both keys and values.
Proposed usage:
import SJSON from '@onedeadpixel/superjson'
import { CriticalSymbol } from 'some-package'
// In application setup
SJSON.symbols.add(CriticalSymbol)
const data = {
[CriticalSymbol]: 'data'
}
const jsonString = SJSON.stringify(data) // => {
// "__sj_symbol[[CritialSymbol]]": "data"
// }
// JSON string sent to another memory instance
const data = SJSON.parse(jsonString) // => {
// [CriticalSymbol]: 'data'
// }
Possible Issues:
- Would rely on the symbols description to reverse it so two symbols with the same description could cause problems. Solution would be allow for description override, e.g.
SJSON.symbols.add(CriticalSymbol, 'sp.CriticalSymbol')