queckezz / fmt-obj

Stringifies any javascript object in your console for CLI inspection :sparkles:
MIT License
443 stars 16 forks source link

experimental references/circular-deps support #4

Closed queckezz closed 7 years ago

queckezz commented 7 years ago

Regarding #3, @jordonbiondo

This PR visualizes cyclic structures. It'll replace any reference with an annotation of where it has seen it first. If we have two keys a and b both pointing to c then it'll look like

js

const c = { prop: 'string' }
console.log(format({ a: c, b: c }))

output

a: { prop: 'string' }
b: [References ~a]

This is not a cyclic structure. However, because we can't have proper cyclic structure detection in javascript as far as I know, this is a fair compromise.

Let me know what you think!