format-json
Advanced tools
Comparing version 1.0.2 to 1.0.3
21
index.js
module.exports = (function() { | ||
function json(o) { return JSON.stringify(o); } | ||
var n = null | ||
@@ -7,9 +8,21 @@ , leadOp = '\n$2$1 ' | ||
, format = | ||
{ terse: function(o) { return JSON.stringify(o); } | ||
{ terse: json | ||
, plain: function(o, i) { return JSON.stringify(o, n, i == n ? 2 : i); } | ||
, diffy: function(o) { | ||
return format.plain(o) | ||
.replace(tailOp, leadOp) | ||
.replace(cuddle, '$1'); | ||
return format.plain(o).replace(tailOp, leadOp).replace(cuddle, '$1'); | ||
} | ||
, space: function(o) { | ||
return JSON.stringify(o, null, 1).replace(/\n */g, ' '); | ||
} | ||
, lines: function(o) { | ||
if ('object' !== typeof o || o == null) return format.terse(o); | ||
if ('[object Array]' === Object.prototype.toString.call(o)) | ||
return '[ '+ o.map(format.space).join('\n, ') + '\n]'; | ||
var res = '', sep = '{ ', key; | ||
for (key in o) { | ||
res += sep + json(key) +': '+ format.space(o[key]); | ||
sep = '\n, '; | ||
} | ||
return res + '\n}'; | ||
} | ||
} | ||
@@ -16,0 +29,0 @@ ; |
{ "name": "format-json" | ||
, "version": "1.0.2" | ||
, "version": "1.0.3" | ||
, "author": "Johan Sundström <oyasumi@gmail.com>" | ||
@@ -4,0 +4,0 @@ , "description": "A JSON formatter module for various text/plain serialization styles" |
@@ -31,2 +31,8 @@ format-json | ||
{"test":"for example","some":[{"nested":0,"things":[]},{}]} | ||
> console.log(json.space(data)); | ||
{ "test": "for example", "some": [ { "nested": 0, "things": [] }, {} ] } | ||
> console.log(json.lines(data)); | ||
{ "test": "for example" | ||
, "some": [ { "nested": 0, "things": [] }, {} ] | ||
} | ||
``` | ||
@@ -33,0 +39,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4753
7
54
51