Skip to content

Instantly share code, notes, and snippets.

@carrierdown
Last active April 16, 2019 07:41
Show Gist options
  • Save carrierdown/021de649fdce3aab969f0062898be6fb to your computer and use it in GitHub Desktop.
Save carrierdown/021de649fdce3aab969f0062898be6fb to your computer and use it in GitHub Desktop.
Drop-in replacement for post()
function debugLog(/* ... args */) {
var result = "";
for (var i = 0; i < arguments.length; i++) {
result += (i !== 0 && i < arguments.length ? " " : "") + debugPost(arguments[i], "");
}
post(result + "\r\n");
}
function debugPost(val, res) {
if (Array.isArray(val)) {
res += "[";
for (var i = 0; i < val.length; i++) {
var currentVal = val[i];
if (currentVal === undefined || currentVal === null) {
res += ".";
continue;
}
res = debugPost(currentVal, res);
if (i < val.length - 1) res += ", ";
}
res += "]";
} else if ((typeof val === "object") && (val !== null)) {
var props = Object.getOwnPropertyNames(val);
res += "{";
for (var ii = 0; ii < props.length; ii++) {
res += props[ii] + ": ";
res = debugPost(val[props[ii]], res);
if (ii < props.length - 1) res += ", ";
}
res += "}";
} else {
res += val;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment