Created
August 25, 2021 17:18
-
-
Save Matsukii/47ae4de7ec745bf28362dfc648f0c37a to your computer and use it in GitHub Desktop.
Check if debug is enabled then print the arguments , if you set the first parameter as log, error or warn, it use the console.<type>
This file contains hidden or 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
| /** | |
| * @description Check if debug is enabled then print the arguments | |
| * if you set the first parameter as log, error or warn, it use | |
| * the console.<type> | |
| * | |
| * @param {...any} args things to print on console | |
| * | |
| * @example log("test: ", 1) // test: 1 | |
| * @example log("error", new Error("Error")) // error Error: Error... | |
| * @example log("warn", "warning") // warn warning | |
| */ | |
| function log(...args){ | |
| const typs = ["log", "warn", "error"]; | |
| let type = typs.includes(args[0]) ? args[0] : "log"; | |
| if(debug) console[type](...args); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment