json-stable-stringify-pretty
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -12,2 +12,3 @@ var json = typeof JSON !== 'undefined' ? JSON : require('jsonify'); | ||
var sortarrays = opts.sortarrays === true; | ||
var undef = opts.undef === true; | ||
@@ -36,3 +37,7 @@ var cmp = opts.cmp && (function (f) { | ||
if (node === undefined) { | ||
if (undef) { | ||
return 'undefined'; | ||
} else { | ||
return; | ||
} | ||
} | ||
@@ -48,3 +53,3 @@ if (pretty && typeof node === 'string') { | ||
for (var i = 0; i < node.length; i++) { | ||
var item = stringify(node, i, node[i], level+1) || json.stringify(null); | ||
var item = stringify(node, i, node[i], level+1); | ||
out.push(indent + space + item); | ||
@@ -51,0 +56,0 @@ } |
{ | ||
"name": "json-stable-stringify-pretty", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A fork of substack's json-stable-stringify: deterministic JSON.stringify() with useful options", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,11 +11,15 @@ var test = require('tape'); | ||
test('object with undefined', function (t) { | ||
t.plan(1); | ||
t.plan(4); | ||
var obj = { a: 3, z: undefined }; | ||
t.equal(stringify(obj), '{"a":3}'); | ||
t.equal(stringify(obj, {undef: true}), '{"a":3,"z":undefined}'); | ||
t.equal(stringify(obj, {undef: true, pretty: true}), '{a:3,z:undefined}'); | ||
t.equal(stringify(obj, {undef: true, pretty: true, space: 2}), '{\n a: 3,\n z: undefined\n}'); | ||
}); | ||
test('array with undefined', function (t) { | ||
t.plan(1); | ||
t.plan(2); | ||
var obj = [4, undefined, 6]; | ||
t.equal(stringify(obj), '[4,null,6]'); | ||
t.equal(stringify(obj), '[4,undefined,6]'); | ||
t.equal(stringify(obj, {undef: true}), '[4,undefined,6]'); | ||
}); | ||
@@ -22,0 +26,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
19054
391
207
3