Comparing version 1.6.2 to 2.0.0
@@ -16,3 +16,2 @@ // Load modules | ||
Date: 'green', | ||
error: 'red', | ||
Function: 'cyan', | ||
@@ -26,5 +25,8 @@ Key: 'white.bold', | ||
Undefined: 'red.inverse', | ||
depth: 'grey', | ||
error: 'red', | ||
path: 'blue' | ||
}, | ||
defaults: { | ||
depth: 2, | ||
plain: false, | ||
@@ -50,4 +52,4 @@ path: false, | ||
internals.path = []; | ||
internals.settings = Hoek.applyToDefaults(internals.defaults, options || {}); | ||
return internals.travel(object, ''); | ||
internals.settings = Hoek.applyToDefaults(internals.defaults, options || {}, true); | ||
return internals.travel(object, '', 0); | ||
}; | ||
@@ -62,9 +64,9 @@ | ||
internals.travel = function (object, path) { | ||
internals.travel = function (object, path, depth) { | ||
var type = global.toString.call(object).split(' ')[1].slice(0, -1); | ||
var type = toString.call(object).split(' ')[1].slice(0, -1); | ||
var format = ''; | ||
if (internals[type]) { | ||
format = internals[type](object, path); | ||
format = internals[type](object, path, depth); | ||
} | ||
@@ -112,3 +114,3 @@ else { | ||
internals.Object = function (object, path) { | ||
internals.Object = internals.process = internals.global = function (object, path, depth) { | ||
@@ -125,2 +127,3 @@ var keys = Object.keys(object); | ||
++depth; | ||
var index = internals.seen.indexOf(object); | ||
@@ -148,3 +151,10 @@ if (index !== -1) { | ||
var keyStr = key.toString(); | ||
out = out + internals.indent() + '' + (internals.printMember(keyStr, longest) + ':') + ' ' + internals.travel(item, path + '.' + keyStr); | ||
if (internals.settings.depth === null || internals.settings.depth + 1 >= depth) { | ||
out = out + internals.indent() + '' + (internals.printMember(keyStr, longest) + ':') + ' ' + internals.travel(item, path + '.' + keyStr, depth); | ||
} | ||
else { | ||
internals.indentLevel = internals.indentLevel - 1; | ||
return internals.colorize('[Object]', 'depth'); | ||
} | ||
if (i !== il - 1) { | ||
@@ -169,3 +179,3 @@ out = out + ','; | ||
internals.Array = function (array, path) { | ||
internals.Array = function (array, path, depth) { | ||
@@ -176,2 +186,3 @@ if (array.length === 0) { | ||
++depth; | ||
var index = internals.seen.indexOf(array); | ||
@@ -195,3 +206,9 @@ if (index !== -1) { | ||
var indexStr = internals.settings.arrayIndex ? '[' + internals.printMember(i, il) + '] ' : ''; | ||
out = out + internals.indent() + '' + indexStr + internals.travel(item, path + '.' + i); | ||
if (internals.settings.depth === null || internals.settings.depth + 1 >= depth) { | ||
out = out + internals.indent() + '' + indexStr + internals.travel(item, path + '.' + i, depth); | ||
} | ||
else { | ||
internals.indentLevel = internals.indentLevel - 1; | ||
return internals.colorize('[Object]', 'depth'); | ||
} | ||
if (i !== il - 1) { | ||
@@ -198,0 +215,0 @@ out = out + ','; |
{ | ||
"name": "purdy", | ||
"version": "1.6.2", | ||
"version": "2.0.0", | ||
"description": "pretty print objects in real purdy colors. Allows clearer visualization of objects than you get from most pretty printers due to colors. It will also print out the complete path to an object, something that's extremly useful for debugging. Purdy will also print out the path to access a variable using Hoek format making it useful on accessing values.", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "lab -a code -t 98 -r html -o coverage.html -r console -o stdout -v" | ||
"test": "lab -a code -t 99 -r html -o coverage.html -r console -o stdout -v" | ||
}, | ||
@@ -9,0 +9,0 @@ "homepage": "https://github.com/danielb2/purdy.js", |
@@ -26,2 +26,3 @@ # Purdy ![build](https://travis-ci.org/danielb2/purdy.js.svg) | ||
* `align` - determines how to align object keys. default: `left` | ||
* `depth` - tells purdy how many times to recurse while formatting the object. This is useful for viewing complicated objects. default: `2`. Set to `null` to recurse indefinitely | ||
@@ -28,0 +29,0 @@ |
@@ -33,3 +33,3 @@ var Code = require('code'); | ||
}; | ||
var out = Purdy.stringify(obj); | ||
var out = Purdy.stringify(obj, { depth: null }); | ||
expect(out).to.equal('{\n \u001b[1m\u001b[37mtheError\u001b[39m\u001b[22m: { \u001b[31m[Error: some bad, bad error]\u001b[39m\n \u001b[1m\u001b[37mwithKey\u001b[39m\u001b[22m: \u001b[33m\'key\'\u001b[39m\n }\n}'); | ||
@@ -64,3 +64,3 @@ done(); | ||
var out = Purdy.stringify(arguments, { plain: true, arrayIndex: false, indent: 2 }); | ||
var out = Purdy.stringify(arguments, { depth: null, plain: true, arrayIndex: false, indent: 2 }); | ||
expect(out).to.equal('[\n \'hello\',\n \'purdy\'\n]'); | ||
@@ -232,3 +232,3 @@ done(); | ||
var out = Purdy.stringify(obj, { plain: false, path: true, align: 'right' }); | ||
var out = Purdy.stringify(obj, { plain: false, path: true, align: 'right', depth: null }); | ||
expect(out).to.equal('{\n \u001b[1m\u001b[37mtravel\u001b[39m\u001b[22m: {\n \u001b[34m// \u001b[39m\u001b[34mtravel.down\u001b[39m\n \u001b[1m\u001b[37mdown\u001b[39m\u001b[22m: {\n \u001b[34m// \u001b[39m\u001b[34mtravel.down.a\u001b[39m\n \u001b[1m\u001b[37m a\u001b[39m\u001b[22m: [\n \u001b[34m// \u001b[39m\u001b[34mtravel.down.a.0\u001b[39m\n [\u001b[1m\u001b[37m0\u001b[39m\u001b[22m] {\n \u001b[34m// \u001b[39m\u001b[34mtravel.down.a.0.path\u001b[39m\n \u001b[1m\u001b[37mpath\u001b[39m\u001b[22m: \u001b[33m\'to get here\'\u001b[39m\n }\n ]\n }\n }\n}'); | ||
@@ -307,3 +307,82 @@ expect(obj).to.deep.equal(orig); | ||
}); | ||
it('obeys depth printing', function (done) { | ||
var obj = { | ||
count: 1, | ||
a: { | ||
count: 2, | ||
b: { | ||
count: 3, | ||
c: { | ||
count: 4 | ||
} | ||
} | ||
} | ||
}; | ||
var out = Purdy.stringify(obj, { depth: 1, arrayIndex: false, plain: true }); | ||
expect(out).to.equal('{\n count: 1,\n a: {\n count: 2,\n b: [Object]\n }\n}'); | ||
done(); | ||
}); | ||
it('should handle depth printing for array', function (done) { | ||
var obj = [[[[[[[[[[]]]]]]]]]]; | ||
var out = Purdy.stringify(obj, { depth: 1, arrayIndex: false, plain: true }); | ||
expect(out).to.equal('[\n [\n [Object]\n ]\n]'); | ||
done(); | ||
}); | ||
it('should print using zero depth', function (done) { | ||
var obj = [[[[[[[[[[]]]]]]]]]]; | ||
var out = Purdy.stringify(obj, { depth: 0, indent: 1, arrayIndex: false, plain: true }); | ||
expect(out).to.equal('[\n [Object]\n]'); | ||
done(); | ||
}); | ||
it('should handle depth printing for mixed', function (done) { | ||
var obj = { | ||
count: 1, | ||
a: { | ||
foo: [[[[[[[[[[]]]]]]]]]], | ||
count: 2, | ||
b: { | ||
count: 3, | ||
c: { | ||
count: 4 | ||
} | ||
} | ||
} | ||
}; | ||
var out = Purdy.stringify(obj, { depth: 1, arrayIndex: false, plain: true }); | ||
expect(out).to.equal('{\n count: 1,\n a: {\n foo: [Object],\n count: 2,\n b: [Object]\n }\n}'); | ||
done(); | ||
}); | ||
it('should handle depth printing using null depth', function (done) { | ||
var obj = { | ||
count: 1, | ||
a: { | ||
count: 2, | ||
b: { | ||
count: 3, | ||
c: { | ||
count: 4 | ||
} | ||
} | ||
} | ||
}; | ||
var out = Purdy.stringify(obj, { depth: null, arrayIndex: false, plain: true }); | ||
expect(out).to.equal('{\n count: 1,\n a: {\n count: 2,\n b: {\n count: 3,\n c: {\n count: 4\n }\n }\n }\n}'); | ||
done(); | ||
}); | ||
}); | ||
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
146493
547
118