-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
executable file
·39 lines (28 loc) · 946 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env node
const QuotesDatabase = require('./db.json'),
program = require('commander'),
cowsay = require('cowsay'),
lolcat = require('lolcatjs'),
wrap = require('word-wrap'),
{ log } = console;
const fetchQuote = () =>{
// Get random number between 0 and QuotesDatabase.quotes.length
const getRandomNumber = (maximumNumber = QuotesDatabase.quotes.length) =>
Math.floor(Math.random() * maximumNumber);
const fetchedQuote = QuotesDatabase.quotes[getRandomNumber()];
// Log output
const text = `
${wrap(fetchedQuote.text, {trim: true, width: 30 })}
${wrap(`-- ${fetchedQuote.author}`, {trim: true, width: 30 })}
`;
const cowsayText = cowsay.say({ text });
lolcat.fromString(cowsayText);
};
// Initialize program
program
.version(require('./package.json').version)
.description('Display a random tech or programming quote');
// Run Qotm
program
.action(() => fetchQuote());
program.parse(process.argv);