Socket
Socket
Sign inDemoInstall

oblo-util

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oblo-util - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

36

oblo-util.js

@@ -1,4 +0,4 @@

// oblo-util.js 0.3.1
// oblo-util.js 0.4.0
// (c) 2013-2011 Martijn M. Schrage, Oblomomov Systems
// (c) 2014-2011 Martijn M. Schrage, Oblomomov Systems
// Oblo-util may be freely distributed under the MIT license.

@@ -53,12 +53,23 @@ // For all details and documentation:

// depth is to prevent hanging on circular objects
util.showJSON = function(json,indent,depth) {
util.addslashes = function( str ) {
return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}
// optional arg maxDepth is to prevent hanging on circular objects
// optional arg indent is to prefix every generated line with indentation
util.showJSON = function(json,maxDepth,indent) {
indent = indent || '';
depth = depth || 0;
maxDepth = typeof maxDepth == 'undefined' ? 20 : maxDepth;
var str = '';
if (!json) {
if (typeof json == 'undefined') {
str += 'undefined';
} else if (json == null) {
str += 'null';
} else if (depth>=10) { // max depth
str += typeof json != 'object' ? json : Array.isArray(json) ? '[...]' : '{...}';
} else if (typeof json == 'string') {
str += '\''+util.addslashes(json)+'\'';
} else if (typeof json != 'object') {
str += json;
} else if (maxDepth<=0) {
str += Array.isArray(json) ? '[...]' : '{...}';
} else if (Array.isArray(json)) {

@@ -69,7 +80,6 @@ if (json.length ==0 )

for (var i = 0; i<json.length; i++)
str += (i==0?'[ ':indent + ', ') + util.showJSON(json[i],' '+indent, depth+1)+'\n';
str += (i==0?'[ ':indent + ', ') + util.showJSON(json[i], maxDepth-1,indent+' ')+'\n';
str += indent + ']';
}
} else if (typeof json == 'object') {
console.log('json: '+json);
var keys = Object.keys(json); // TODO: use underscore version for safety

@@ -81,8 +91,8 @@ if (keys.length ==0 )

str += (i==0?'{ ':indent + ', ') + keys[i] + ':' +
(typeof json[keys[i]] == 'object' ? '\n' + indent +' ' : ' ') + // for object children start new line
util.showJSON(json[keys[i]],' '+indent, depth+1)+'\n';
(typeof json[keys[i]] == 'object' && json[keys[i]] != null ? '\n' + indent +' ' : ' ') + // for object children start new line
util.showJSON(json[keys[i]], maxDepth-1,indent+' ')+'\n';
str += indent + '}';
}
} else {
str += json;
console.error('util.showJSON: internal error, unhandled type: \'' + typeof json + '\'');
}

@@ -89,0 +99,0 @@ return str;

{
"name": "oblo-util",
"version": "0.3.2",
"version": "0.4.0",
"description": "Utilities module suitable for both Node.js and client-side use",

@@ -5,0 +5,0 @@ "main": "oblo-util.js",

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