superjson icon indicating copy to clipboard operation
superjson copied to clipboard

Add Symbol Support

Open nrdobie opened this issue 5 years ago • 0 comments

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')

nrdobie avatar Jul 19 '19 14:07 nrdobie