Last active
September 24, 2020 15:37
-
-
Save amygrinn/ad0cfd177388527d566c7d6c1ad59119 to your computer and use it in GitHub Desktop.
Create a random theme with chalk: https://www.npmjs.com/package/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, { Chalk } from 'chalk'; | |
const modifiers: (keyof Chalk)[] = [ | |
'bold', | |
'dim', | |
'italic', | |
'underline', | |
'inverse', | |
]; | |
const colors: (keyof Chalk)[] = [ | |
'black', | |
'red', | |
'green', | |
'yellow', | |
'blue', | |
'magenta', | |
'cyan', | |
'white', | |
'blackBright', | |
'redBright', | |
'greenBright', | |
'yellowBright', | |
'blueBright', | |
'magentaBright', | |
'cyanBright', | |
'whiteBright', | |
]; | |
const backgrounds: (keyof Chalk)[] = [ | |
'bgBlack', | |
'bgRed', | |
'bgGreen', | |
'bgYellow', | |
'bgBlue', | |
'bgMagenta', | |
'bgCyan', | |
'bgWhite', | |
'bgBlackBright', | |
'bgRedBright', | |
'bgGreenBright', | |
'bgYellowBright', | |
'bgBlueBright', | |
'bgMagentaBright', | |
'bgCyanBright', | |
'bgWhiteBright', | |
]; | |
export default (): Chalk => { | |
const modifier = modifiers[Math.floor(Math.random() * modifiers.length)]; | |
const color = colors[Math.floor(Math.random() * colors.length)]; | |
const background = | |
backgrounds[Math.floor(Math.random() * backgrounds.length)]; | |
let theme = chalk[modifier] as Chalk; | |
theme = theme[color] as Chalk; | |
theme = theme[background] as Chalk; | |
return theme; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment