Last active
April 16, 2019 07:41
-
-
Save carrierdown/021de649fdce3aab969f0062898be6fb to your computer and use it in GitHub Desktop.
Drop-in replacement for post()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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