Skip to content

Feature request: Support for Symbol-keys #6

@ulrichb

Description

@ulrichb

Symbol-typed keys (and their values) are also something which gets lost in a JSON round-trip.

So it would be nice if typeson.js also supports key-rivival (next to value-revival).

This would mean:

  • When iterating over object keys additionally iterate over symbols using Object.getOwnPropertySymbols() (and process also their values).
  • Provide a possibility to register symbols to be able to test for a symbol using key === registeredSymbol and to use the registeredSymbol-value to revive it again, e.g.:
const mySymbol = Symbol();
const otherSymbol = Symbol("symbol with description");

new Typeson().registerSymbolKeys({
    MySymbol: mySymbol,
    OtherSymbol: otherSymbol,
});
  • Change the symbol-keys to string-keys during encapsulate() and reverse it during revive().
    • Here we need to avoid conflicts with equally named string-keys. This could be done by prefixing/postfixing them with a fixed value, or maybe by a random value (+ test loop).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions