Skip to content

Instantly share code, notes, and snippets.

@mathieucaroff
Created June 28, 2019 11:26
Show Gist options
  • Save mathieucaroff/6851b295c1e4bffafce362d0a1ae00f0 to your computer and use it in GitHub Desktop.
Save mathieucaroff/6851b295c1e4bffafce362d0a1ae00f0 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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