You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Circular dependency detection/handling (infinite loops may occur as it is)
94
93
95
94
Feel free to contribute.
96
95
97
96
## Technical Notes
98
97
Uses toJSON when available, and JSON.stringify to stringify everything but objects and arrays.
99
98
Streams with ObjectMode=true are output as arrays while ObjectMode=false output as a concatinated string (each chunk is piped with transforms).
100
99
100
+
Circular structures are handled using a WeakMap based implementation of [Douglas Crockfords Decycle method](https://github.com/douglascrockford/JSON-js/blob/master/cycle.js). To restore circular structures; use Crockfords Retrocycle method on the parsed object.
it('{a: a, b: [a, { a: a },,a.b.1]} should be {"a":"~","b":["~",{"a":"~"},null,"~b~1"]}',createTest(circularData1,'{"a":"~","b":["~",{"a":"~"},null,"~b~1"]}'));
142
+
describe('circular structure',function(){
143
+
144
+
letcircularData0={};
145
+
circularData0.a=circularData0;
146
+
it(`{ a: a } should be {"a":{"$ref":"$"}}`,createTest(circularData0,`{"a":{"$ref":"$"}}`));
it('{a: a, b: [a, { a: a },,ReadableStream(b.1)]} should be {"a":{"$ref":"$"},"b":[{"$ref":"$"},{"a":{"$ref":"$"}},null,[{"$ref":"$[\\"b\\"][1]"}]]}',createTest(circularData1,'{"a":{"$ref":"$"},"b":[{"$ref":"$"},{"a":{"$ref":"$"}},null,[{"$ref":"$[\\"b\\"][1]"}]]}'));
155
+
156
+
letcircularData2={};
157
+
letdata2={
158
+
a: 'deep'
159
+
};
160
+
circularData2.a=Promise.resolve({
161
+
b: data2
162
+
});
163
+
circularData2.b=data2;
164
+
it(`{ a: Promise({ b: { a: 'deep' } }), b: a.b } should be {"a":{"b":{"a":"deep"}},"b":{"$ref":"$[\\"a\\"][\\"b\\"]"}}`,createTest(circularData2,`{"a":{"b":{"a":"deep"}},"b":{"$ref":"$[\\"a\\"][\\"b\\"]"}}`));
0 commit comments