Last active
February 16, 2021 13:44
-
-
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.
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
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) | |
} | |
} |
Author
calag4n
commented
May 22, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment