json-viewer
Version:
Pretty JSON viewer for the terminal
46 lines (36 loc) • 2.12 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.prettyPrint = undefined;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _prettyPrintKey = require('./pretty-print-key');
var _prettyPrintString = require('./pretty-print-string');
var _prettyPrintArray = require('./pretty-print-array');
var _prettyPrintObject = require('./pretty-print-object');
var prettyPrint = exports.prettyPrint = function prettyPrint() {
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var indent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var colorOutput = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var addComma = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
var isString = typeof value === 'string';
var isArray = value instanceof Array;
var isObject = value !== null && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object';
var isSymbol = (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'symbol';
var hasKey = key !== null;
if (hasKey) {
(0, _prettyPrintKey.prettyPrintKey)(key, indent, colorOutput);
}
if (isString) {
(0, _prettyPrintString.prettyPrintString)('"' + value + '"', hasKey ? 0 : indent, colorOutput, addComma);
} else if (isArray) {
(0, _prettyPrintArray.prettyPrintArray)(value, indent, colorOutput, addComma);
} else if (isObject) {
(0, _prettyPrintObject.prettyPrintObject)(value, indent, colorOutput, addComma);
} else if (isSymbol) {
(0, _prettyPrintString.prettyPrintString)(Symbol.toString(), indent, colorOutput, addComma);
} else {
(0, _prettyPrintString.prettyPrintString)(value, hasKey ? 0 : indent, colorOutput, addComma);
}
};
;