stream-stringify
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -15,3 +15,3 @@ // Generated by CoffeeScript 1.9.2 | ||
function StreamStringify(options1) { | ||
var defaultOutputFormat, outputTokens, prevTabCharacter, ref, ref1, ref2, ref3, ref4, tabCharacter; | ||
var defaultOutputFormat, outputTokens, ref, ref1, ref2, ref3, ref4; | ||
this.options = options1 != null ? options1 : {}; | ||
@@ -55,7 +55,7 @@ this.ended = this._ended = this.destroyed = this.stopped = this.hasNested = this.isNested = false; | ||
} | ||
tabCharacter = StreamStringify._tabCharacter(this.tabWidth * this.tabLevel); | ||
prevTabCharacter = StreamStringify._tabCharacter(this.tabWidth * (this.tabLevel - 1)); | ||
this.op += "\n" + tabCharacter; | ||
this.sep += "\n" + tabCharacter; | ||
this.cl = "\n" + prevTabCharacter + this.cl; | ||
this.tabCharacter = StreamStringify._tabCharacter(this.tabWidth * this.tabLevel); | ||
this.prevTabCharacter = StreamStringify._tabCharacter(this.tabWidth * (this.tabLevel - 1)); | ||
this.op += "\n" + this.tabCharacter; | ||
this.sep += "\n" + this.tabCharacter; | ||
this.cl = "\n" + this.prevTabCharacter + this.cl; | ||
} | ||
@@ -65,5 +65,7 @@ this.on('end', function() { | ||
if (this.autoDestroy) { | ||
return process.nextTick(function() { | ||
return this.destroy(); | ||
}); | ||
return process.nextTick((function(_this) { | ||
return function() { | ||
return _this.destroy(); | ||
}; | ||
})(this)); | ||
} | ||
@@ -81,5 +83,5 @@ }); | ||
return ((function() { | ||
var i, ref, results; | ||
var j, ref, results; | ||
results = []; | ||
for (k = i = 1, ref = width; 1 <= ref ? i <= ref : i >= ref; k = 1 <= ref ? ++i : --i) { | ||
for (k = j = 1, ref = width; 1 <= ref ? j <= ref : j >= ref; k = 1 <= ref ? ++j : --j) { | ||
results.push(" "); | ||
@@ -94,9 +96,16 @@ } | ||
StreamStringify._formatEntity = function(data) { | ||
switch (typeof data) { | ||
case 'string' && data.length: | ||
StreamStringify.prototype._formatEntity = function(data) { | ||
var dataLines, i, j, ref; | ||
switch (false) { | ||
case !(typeof data === "string" && data.length): | ||
return "\"" + data + "\""; | ||
case 'object': | ||
case typeof data !== 'object': | ||
if (this.prettyFormat) { | ||
return JSON.stringify(data, null, this.tabWidth); | ||
data = JSON.stringify(data, 2, this.tabWidth); | ||
dataLines = data.split('\n'); | ||
for (i = j = 1, ref = dataLines.length - 1; 1 <= ref ? j <= ref : j >= ref; i = 1 <= ref ? ++j : --j) { | ||
dataLines[i] = this.tabCharacter + dataLines[i]; | ||
} | ||
data = dataLines.join('\n'); | ||
return data; | ||
} else { | ||
@@ -125,3 +134,3 @@ return JSON.stringify(data); | ||
} | ||
return this.write(this._applySeparator("" + (this._keyPrefix(key)) + (StreamStringify._formatEntity(value)))); | ||
return this.write(this._applySeparator("" + (this._keyPrefix(key)) + (this._formatEntity(value)))); | ||
}; | ||
@@ -134,3 +143,3 @@ | ||
} | ||
return this.write(this._applySeparator(StreamStringify._formatEntity(data))); | ||
return this.write(this._applySeparator(this._formatEntity(data))); | ||
}; | ||
@@ -137,0 +146,0 @@ |
{ | ||
"name": "stream-stringify", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "Stringify nested JSON through streams.", | ||
@@ -5,0 +5,0 @@ "main": "lib/stream-stringify.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29933
267