superjson
superjson copied to clipboard
Add Function Support
This would add support for Functions as values.
Proposed usage:
import SJSON, { registerFunction } from '@onedeadpixel/superjson'
// In application setup
registerFunction(SJSON)
const data = {
myFunc: (status) => console.log('MY LOG:', status)
}
const jsonString = SJSON.stringify(data) // => {
// "myFunc": {
// "__sj_type": "Function",
// "__sj_value": "(status) => console.log('MY LOG:', status)"
// }
// }
// JSON string sent to another memory instance
const data = SJSON.parse(jsonString) // => {
// myFunc: (status) => console.log('MY LOG:', status)
// }
Possible Issues:
- Functions could pose some level of security risk so they would not be enabled by default.