Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-stable-stringify-pretty

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-stable-stringify-pretty - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

test/mongodb.js

11

index.js

@@ -12,2 +12,3 @@ var json = typeof JSON !== 'undefined' ? JSON : require('jsonify');

var sortarrays = opts.sortarrays === true;
var undef = opts.undef === true;

@@ -29,2 +30,6 @@ var cmp = opts.cmp && (function (f) {

// A custom hack for mongodb objectids.
if (node && node.toHexString && typeof node.toHexString === 'function') {
node = 'id$' + node.toHexString();
}
if (node && node.toJSON && typeof node.toJSON === 'function') {

@@ -37,3 +42,7 @@ node = node.toJSON();

if (node === undefined) {
if (undef) {
return 'undefined';
} else {
return;
}
}

@@ -49,3 +58,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);

@@ -52,0 +61,0 @@ }

2

package.json
{
"name": "json-stable-stringify-pretty",
"version": "1.0.1",
"version": "1.0.2",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc