Skip to content

Instantly share code, notes, and snippets.

@calag4n
Last active February 16, 2021 13:44
Show Gist options
  • Save calag4n/8fad1e9a1437b72c659a36c4c95b8f20 to your computer and use it in GitHub Desktop.
Save calag4n/8fad1e9a1437b72c659a36c4c95b8f20 to your computer and use it in GitHub Desktop.
The function displays more visible logs in console (cleared by default), make table of arrays and group elements when a string is passed in isMapped argument. See example below, in comments.
export const log = (obj, clear = true, mapKey) => {
const title = "font-size: 19px; color: #e65264"
if (clear) {
console.clear()
}
if (mapKey) {
console.group(mapKey)
obj.map(o => console.log(o))
console.groupEnd(mapKey)
} else if (Array.isArray(obj)) {
console.log("%c Array 👇️", title)
console.table(obj)
} else if (typeof obj === "string") {
console.log("%c String 👇️", title)
console.log(`%c ${obj}`, "font-size: 14px; color: yellow")
} else {
console.log("%c Object 👇️", title)
console.log(obj)
}
}
@calag4n
Copy link
Author

calag4n commented May 22, 2020

log(smth)

Capture d’écran de 2020-05-22 11-38-43

@calag4n
Copy link
Author

calag4n commented May 22, 2020

log(arr)

Capture d’écran de 2020-05-22 11-44-27

@calag4n
Copy link
Author

calag4n commented May 22, 2020

    arr.forEach((el, i) => {

      log([el.obj, el.arr, el.str], false, `arr index-${i}`)

    })

Do not forget to provide false to clear argument for displaying all iterations

Capture d’écran de 2020-05-22 11-48-57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment