Skip to content

Commit 9f08884

Browse files
committed
Add option to disable decycling
1 parent 4393d58 commit 9f08884

File tree

5 files changed

+1301
-8
lines changed

5 files changed

+1301
-8
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ JSON Stringify as a Readable Stream with rescursive resolving of any readable st
1414
- Streams (ObjectMode) are piped through a transform which pipes the data through JSONStreamStreamify (enabling recursive resolving)
1515
- Streams (Non-ObjectMode) is stringified and piped
1616
- Output is streamed optimally with as small chunks as possible
17+
- Decycling using Douglas Crockfords Cycle algorithm
1718
- Great memory management with reference release post process (When a key and value has been processed the value is dereferenced)
1819
- Stream pressure handling
1920

@@ -25,10 +26,12 @@ npm install --save json-stream-stringify
2526

2627
## API
2728

28-
### JSONStreamStringify(value[, replacer])
29+
### JSONStreamStringify(value[, replacer[, spaces[, noDecycle]]])
2930
Convert value to JSON string. Returns a readable stream.
3031
- ``value`` Any data to convert to JSON.
3132
- ``replacer`` Optional ``Function(key, value)`` or ``Array``.
33+
- ``spaces`` Optional ``String`` or ``Number`` **Not yet implemented**
34+
- ``noDecycle`` Optional ``Boolean`` Set to ``true`` to disable decycling.
3235
As a function the returned value replaces the value associated with the key. [Details](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)
3336
As an array all other keys are filtered. [Details](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Example_with_an_array)
3437

jsonStreamify.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class JSONStreamify extends CoStream {
1515
* _makeGenerator(value, replacer) {
1616
let insertSeparator = false;
1717
for (let obj of this._iter) {
18-
//console.log(obj, insertSeparator);
19-
2018
if (obj.state === 'close') {
2119
insertSeparator = true;
2220
yield this.push(obj.type === Object ? '}' : ']');
@@ -97,6 +95,6 @@ class JSONStreamify extends CoStream {
9795
}
9896
}
9997

100-
module.exports = function(obj, replacer) {
101-
return new JSONStreamify(obj, replacer);
98+
module.exports = function (value, replacer, space, noDecycle) {
99+
return new JSONStreamify(value, replacer, space, noDecycle ? { has: () => false, set: () => undefined } : undefined);
102100
};

0 commit comments

Comments
 (0)