+14
-4
@@ -5,3 +5,2 @@ const _ = require('lodash'); | ||
| const maxItems = 30; | ||
| const internals = ['Array', 'Object', 'Function']; | ||
@@ -38,3 +37,14 @@ | ||
| function stringify(object) { | ||
| function stringify(object, addr, options) { | ||
| if (addr) { | ||
| if (!options && _.isPlainObject(addr)) { | ||
| options = addr; | ||
| addr = undefined; | ||
| } else { | ||
| object = _.get(object, addr); | ||
| } | ||
| } | ||
| const { maxItems = 30 } = options || {}; | ||
| return stringifyObject(object, { | ||
@@ -70,5 +80,5 @@ indent: ' ', | ||
| function print(object) { | ||
| function print(object, addr, options) { | ||
| // eslint-disable-next-line no-console | ||
| console.log(stringify(object)); | ||
| console.log(stringify(object, addr, options)); | ||
| } | ||
@@ -75,0 +85,0 @@ |
+23
-6
| { | ||
| "name": "q-i", | ||
| "version": "1.0.0", | ||
| "description": "quickly inspect Node.js objects", | ||
| "version": "1.1.0", | ||
| "description": "Node.js objects inspector with color highlighting", | ||
| "author": { | ||
@@ -13,3 +13,3 @@ "name": "Artem Sapegin", | ||
| "engines": { | ||
| "node": ">=4" | ||
| "node": ">=6" | ||
| }, | ||
@@ -26,3 +26,4 @@ "main": "index.js", | ||
| "test:coverage": "jest --coverage", | ||
| "test": "npm run test:jest" | ||
| "test": "npm run test:jest", | ||
| "precommit": "lint-staged" | ||
| }, | ||
@@ -38,3 +39,6 @@ "keywords": [ | ||
| "stringify", | ||
| "json" | ||
| "json", | ||
| "color", | ||
| "syntax", | ||
| "highlight" | ||
| ], | ||
@@ -45,3 +49,5 @@ "devDependencies": { | ||
| "eslint-plugin-prettier": "^2.3.1", | ||
| "husky": "^0.14.3", | ||
| "jest": "^21.1.0", | ||
| "lint-staged": "^4.2.1", | ||
| "prettier": "^1.7.0" | ||
@@ -53,3 +59,14 @@ }, | ||
| "stringify-object": "^3.2.0" | ||
| }, | ||
| "lint-staged": { | ||
| "*.js": [ | ||
| "eslint --fix", | ||
| "git add" | ||
| ] | ||
| }, | ||
| "release": { | ||
| "analyzeCommits": "semantic-release-tamia/analyzeCommits", | ||
| "generateNotes": "semantic-release-tamia/generateNotes", | ||
| "verifyRelease": "semantic-release-tamia/verifyRelease" | ||
| } | ||
| } | ||
| } |
+50
-3
@@ -1,5 +0,17 @@ | ||
| # q-i: quickly inspect Node.js objects | ||
| # q-i: Node.js objects inspector with color highlighting | ||
| [](https://www.npmjs.com/package/q-i) | ||
| [](https://travis-ci.org/sapegin/q-i) | ||
| Useful for debugging big objects, like webpack configuration. | ||
|  | ||
| ## Features | ||
| * Compact and readable output | ||
| * No unnecessary quotes | ||
| * Color highlighted | ||
| * Collapses huge arrays and objects (more than 30 items by default) | ||
| ## Installation | ||
@@ -16,6 +28,41 @@ | ||
| print({ a: 42 }); | ||
| console.log(stringify({ a: 42 })); | ||
| const obj = { a: { x: 41, y: { z: 42 } } }; | ||
| // Print whole object | ||
| print(obj); | ||
| console.log(stringify(obj)); | ||
| /* => | ||
| { | ||
| a: { | ||
| x: 41, | ||
| y: { | ||
| z: 42 | ||
| } | ||
| } | ||
| } | ||
| */ | ||
| // Print part of an object | ||
| print(obj, 'a.y'); | ||
| console.log(stringify(obj, 'a.y')); | ||
| /* => | ||
| { | ||
| z: 42 | ||
| } | ||
| */ | ||
| ``` | ||
| ## Options | ||
| ```js | ||
| print(obj, { maxItems: Infinity }) | ||
| print(obj, 'a.y', { maxItems: Infinity }) | ||
| stringify(obj, { maxItems: Infinity }) | ||
| stringify(obj, 'a.y', { maxItems: Infinity }) | ||
| ``` | ||
| ### `maxItems` (default: 30) | ||
| Collapse arrays with more than `maxItems` items and objects with more than `maxItems` keys. | ||
| ## Change log | ||
@@ -22,0 +69,0 @@ |
6108
35.61%66
13.79%80
142.42%7
40%