Skip to content

Instantly share code, notes, and snippets.

@Matsukii
Created August 25, 2021 17:18
Show Gist options
  • Select an option

  • Save Matsukii/47ae4de7ec745bf28362dfc648f0c37a to your computer and use it in GitHub Desktop.

Select an option

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>
/**
* @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