serialize-javascript icon indicating copy to clipboard operation
serialize-javascript copied to clipboard

Any plans to support circular structures?

Open Judahh opened this issue 4 years ago • 3 comments

Judahh avatar Feb 15 '21 10:02 Judahh

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

juandopazo avatar Feb 15 '21 22:02 juandopazo

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.

undefined-moe avatar Apr 25 '22 14:04 undefined-moe

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

EmileSonneveld avatar Jun 22 '22 12:06 EmileSonneveld