Last active
August 19, 2019 07:29
-
-
Save shqld/f2c3ea2b93b3960093fc60b911a5a773 to your computer and use it in GitHub Desktop.
Colored console with chalk
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
import chalk from 'chalk'; | |
export const initChalk = ({ error = chalk.redBright, warn = chalk.yellowBright } = {}) => { | |
// disable coloring e.g. when piped like `2> err.log` | |
if (typeof process !== 'undefined' && !process.stderr.isTTY) { | |
return; | |
} | |
if (error) { | |
const defaultError = console.error.bind(console); | |
console.error = (...args) => defaultError(error(args.shift()), ...args); | |
} | |
if (warn) { | |
const defaultWarn = console.warn.bind(console); | |
console.warn = (...args) => defaultWarn(warn(args.shift()), ...args); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment