json-stable-stringify
Advanced tools
Comparing version 0.0.1 to 0.1.0
18
index.js
@@ -6,2 +6,4 @@ var json = typeof JSON !== 'undefined' ? JSON : require('jsonify'); | ||
if (typeof opts === 'function') opts = { cmp: opts }; | ||
var space = opts.space || ''; | ||
if (typeof space === 'number') space = Array(space+1).join(' '); | ||
var cmp = opts.cmp && (function (f) { | ||
@@ -17,3 +19,5 @@ return function (node) { | ||
return (function stringify (node) { | ||
return (function stringify (node, level) { | ||
var indent = space ? ('\n' + new Array(level + 1).join(space)) : ''; | ||
var colonSeparator = space ? ': ' : ':'; | ||
if (typeof node !== 'object' || node === null) { | ||
@@ -25,5 +29,6 @@ return json.stringify(node); | ||
for (var i = 0; i < node.length; i++) { | ||
out.push(stringify(node[i])); | ||
var item = stringify(node[i], level+1); | ||
out.push(indent + space + item); | ||
} | ||
return '[' + out.join(',') + ']'; | ||
return '[' + out.join(',') + indent + ']'; | ||
} | ||
@@ -35,7 +40,8 @@ else { | ||
var key = keys[i]; | ||
out.push(stringify(key) + ':' + stringify(node[key])); | ||
var keyValue = stringify(key,0) + colonSeparator + stringify(node[key],level+1); | ||
out.push(indent + space + keyValue); | ||
} | ||
return '{' + out.join(',') + '}'; | ||
return '{' + out.join(',') + indent + '}'; | ||
} | ||
})(obj); | ||
})(obj, 0); | ||
}; | ||
@@ -42,0 +48,0 @@ |
{ | ||
"name": "json-stable-stringify", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "deterministic JSON.stringify() with custom sorting to get deterministic hashes from stringified results", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
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
9248
13
148
125