Skip to content

Instantly share code, notes, and snippets.

@khriztianmoreno
Last active November 20, 2019 22:57
Show Gist options
  • Save khriztianmoreno/b3411db469c8d24a1b2ea10f7a88bb59 to your computer and use it in GitHub Desktop.
Save khriztianmoreno/b3411db469c8d24a1b2ea10f7a88bb59 to your computer and use it in GitHub Desktop.
Run JavaScript in the terminal from a gist with npx
#!/usr/bin/env node
const figlet = require('figlet');
const inquirer = require('inquirer');
const colors = require('colors/safe');
const COLORS = [
'black',
'red',
'green',
'yellow',
'blue',
'magenta',
'cyan',
'white'
];
inquirer
.prompt([
{
type: 'input',
name: 'name',
message: "What's your name"
},
{
type: 'list',
name: 'color',
message: 'Choose a text color',
choices: COLORS,
default: 'white'
},
{
type: 'list',
name: 'bgColor',
message: 'Choose a background color',
choices: COLORS,
default: 'black'
}
]).then(({name, color, bgColor})=>{
name = name.trim()==='' ? "C3PO":name;
bgColor = `bg${bgColor.charAt(0).toUpperCase() + bgColor.slice(1)}`;
figlet(name, function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(colors[color][bgColor](data));
});
})
{
"name": "print-your-name",
"version": "1.0.0",
"description": "Fancy print your name on the terminal with colors",
"main": "index.js",
"scripts": {},
"repository": {
"type": "gist"
},
"bin": {
"presentation": "./index.js"
},
"keywords": [
"name",
"print",
"terminal"
],
"author": "",
"license": "MIT",
"dependencies": {
"colors": "^1.3.2",
"figlet": "^1.2.1",
"inquirer": "^6.2.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment