Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var MAX_DEPTH = 20
export var expandedLog = (obj: Record<string, unknown>, depth: number = 0) => {
var [[name, item]] = Object.entries(obj)
if (depth < MAX_DEPTH && typeof item === 'object' && item) {
var typeString = Object.prototype.toString.call(item)
var objType = typeString.replace(/\[object (.*)\]/, '$1')
console.group(`${name}: ${objType}`)
Object.entries(item).forEach(([key, value]: any) => {
log({ [key]: value }, depth + 1)
})
console.groupEnd()
} else {
var itemString = `${item}`
if (typeof item === 'string') {
itemString = `"${itemString}"`
}
console.log(`${name}: ${itemString}`)
return
}
}
@mathieucaroff

This comment has been minimized.

Copy link
Owner Author

mathieucaroff commented Jun 28, 2019

var structure = { a: "A", b: "B", arr: [200, 400] }
expandedLog({ structure })
expandedLog({ watchThis: structure.arr })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.