Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

js-object-pretty-print

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-object-pretty-print - npm Package Compare versions

Comparing version
0.2.0
to
0.3.0
+91
-52
index.js
"use strict";
module.exports.pretty = function (jsObject, indentLength, outputTo, fullFunction) {
module.exports.pretty = function(jsObject, indentLength, outputTo, fullFunction) {
var indentString,

@@ -22,14 +22,58 @@ newLine,

TYPES = {
'undefined' : 'undefined',
'number' : 'number',
'boolean' : 'boolean',
'string' : 'string',
'undefined': 'undefined',
'number': 'number',
'boolean': 'boolean',
'string': 'string',
'[object Function]': 'function',
'[object RegExp]' : 'regexp',
'[object Array]' : 'array',
'[object Date]' : 'date',
'[object Error]' : 'error'
'[object RegExp]': 'regexp',
'[object Array]': 'array',
'[object Date]': 'date',
'[object Error]': 'error'
};
valueType = function (o) {
if (!Object.keys) {
Object.keys = (function() {
'use strict';
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({
toString: null
}).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;
return function(obj) {
if (typeof obj !== 'function' && (typeof obj !== 'object' || obj === null)) {
throw new TypeError('Object.keys called on non-object');
}
var result = [],
prop, i;
for (prop in obj) {
if (hasOwnProperty.call(obj, prop)) {
result.push(prop);
}
}
if (hasDontEnumBug) {
for (i = 0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) {
result.push(dontEnums[i]);
}
}
}
return result;
};
}());
}
valueType = function(o) {
var type = TYPES[typeof o] || TYPES[TOSTRING.call(o)] || (o ? 'object' : 'null');

@@ -39,3 +83,3 @@ return type;

repeatString = function (src, length) {
repeatString = function(src, length) {
var dst = '',

@@ -50,3 +94,3 @@ index;

prettyObjectJSON = function (object, indent) {
prettyObjectJSON = function(object, indent) {
var value = [],

@@ -56,7 +100,5 @@ property;

indent += indentString;
for (property in object) {
if (object.hasOwnProperty(property)) {
value.push(indent + '"' + property + '": ' + pretty(object[property], indent));
}
}
Object.keys(object).forEach(function (property) {
value.push(indent + '"' + property + '": ' + pretty(object[property], indent));
});

@@ -66,3 +108,3 @@ return value.join(newLineJoin) + newLine;

prettyObjectPrint = function (object, indent) {
prettyObjectPrint = function(object, indent) {
var value = [],

@@ -72,12 +114,9 @@ property;

indent += indentString;
for (property in object) {
if (object.hasOwnProperty(property)) {
value.push(indent + property + ': ' + pretty(object[property], indent));
}
}
Object.keys(object).forEach(function (property) {
value.push(indent + property + ': ' + pretty(object[property], indent));
});
return value.join(newLineJoin) + newLine;
};
prettyArray = function (array, indent) {
prettyArray = function(array, indent) {
var index,

@@ -95,3 +134,3 @@ length = array.length,

functionSignature = function (element) {
functionSignature = function(element) {
var signatureExpression,

@@ -107,3 +146,3 @@ signature;

pretty = function (element, indent, fromArray) {
pretty = function(element, indent, fromArray) {
var type;

@@ -115,36 +154,36 @@

switch (type) {
case 'array':
visited.push(element);
return fromArray + '[' + newLine + prettyArray(element, indent) + indent + ']';
case 'array':
visited.push(element);
return fromArray + '[' + newLine + prettyArray(element, indent) + indent + ']';
case 'boolean':
return fromArray + (element ? 'true' : 'false');
case 'boolean':
return fromArray + (element ? 'true' : 'false');
case 'date':
return fromArray + '"' + element.toString() + '"';
case 'date':
return fromArray + '"' + element.toString() + '"';
case 'number':
return fromArray + element;
case 'number':
return fromArray + element;
case 'object':
visited.push(element);
return fromArray + '{' + newLine + prettyObject(element, indent) + indent + '}';
case 'object':
visited.push(element);
return fromArray + '{' + newLine + prettyObject(element, indent) + indent + '}';
case 'string':
return fromArray + JSON.stringify(element);
case 'string':
return fromArray + JSON.stringify(element);
case 'function':
return fromArray + functionSignature(element);
case 'function':
return fromArray + functionSignature(element);
case 'undefined':
return fromArray + 'undefined';
case 'undefined':
return fromArray + 'undefined';
case 'null':
return fromArray + 'null';
case 'null':
return fromArray + 'null';
default:
if (element.toString) {
return fromArray + '"' + element.toString() + '"';
}
return fromArray + '<<<ERROR>>> Cannot get the string value of the element';
default:
if (element.toString) {
return fromArray + '"' + element.toString() + '"';
}
return fromArray + '<<<ERROR>>> Cannot get the string value of the element';
}

@@ -151,0 +190,0 @@ }

{
"name": "js-object-pretty-print",
"version": "0.2.0",
"version": "0.3.0",
"description": "Serializes a javascript object to a printable string. String is formatted to be used in either pure text environments, like a console log or in HTML or to create a JSON output.",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet