yahoo / serialize-javascript

Serialize JavaScript to a superset of JSON that includes regular expressions and functions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any plans to support circular structures?

Judahh opened this issue · comments

Hi @Judahh, unless I'm mistaken I believe the only way to support them would be to create a new protocol and a new "parse" method. That would go a bit past what I think the original design goal was (to be able to just eval the serialized result).

I think its possible to serialize as the following:

(() => {
  const t = {}; // some base structure
  t.foo = t; // do some magic
  return t;
})();

This becomes a little bit tricky, and I don't know is this feature really needed in most use cases.

commented

I made a tool that does what serialize-javascript does, but also added support for circular references, duplicate objects and more:
https://github.com/emilesonneveld/serialize-to-js