-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
200 lines (188 loc) · 7.28 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env node
/**
* Print the current date and time
*
* @return {String}
*/
"use strict";
var genericQuoteList = require('./data/generic-quotes.json');
var moviesQuoteList = require('./data/movies-quotes.json');
var seriesQuoteList = require('./data/series-quotes.json');
var _ = require("underscore");
const chalkAnimation = require('chalk-animation');
var inputEmotion = "";
var matchingQuote = "";
var genericQuoteListLength = "";
var moviesQuoteListLength = "";
var seriesQuoteListLength = "";
var index = 0;
var genericQuoteObject = { "quote": "", "author": "" };
var moviesQuoteObject = { "quote": "", "movie": "" };
var seriesQuoteObject = { "quote": "", "series": "" };
genericQuoteListLength = Object.keys(genericQuoteList).length;
moviesQuoteListLength = Object.keys(moviesQuoteList).length;
seriesQuoteListLength = Object.keys(seriesQuoteList).length;
module.exports = {
getQuote: function (inpString) {
if (inpString) {
var string = inpString.replace(/^\s+|\t+|\s+$/g, "");
inputEmotion = string.toLowerCase().replace(/\s+/g, " ");
_.each(genericQuoteList, function (quote) {
if (quote.text.toLowerCase().includes(inputEmotion)) {
matchingQuote = quote.text;
return;
}
});
} else {
matchingQuote = getRandomQuote(genericQuoteListLength, genericQuoteList);
}
return matchingQuote;
},
getQuoteWithAuthor: function (inpString) {
if (inpString) {
inputEmotion = inpString.toLowerCase().trim();
_.each(genericQuoteList, function (quote) {
if (quote.text.toLowerCase().includes(inputEmotion)) {
genericQuoteObject.quote = quote.text;
genericQuoteObject.author = quote.from;
return;
}
});
if (genericQuoteObject.quote === "") {
genericQuoteObject = getRandomQuoteWithDetails('G');
}
}
else {
genericQuoteObject = getRandomQuoteWithDetails('G');
}
return genericQuoteObject;
},
getMovieQuote: function (inpString) {
if (inpString) {
inputEmotion = inpString.toLowerCase().trim();
_.each(moviesQuoteList, function (quote) {
if (quote.text.toLowerCase().includes(inputEmotion)) {
matchingQuote = quote.text;
return;
}
});
} else {
matchingQuote = getRandomQuote(moviesQuoteListLength, moviesQuoteList);
}
return matchingQuote;
},
getQuoteWithMovieName: function (inpString) {
if (inpString) {
inputEmotion = inpString.toLowerCase().trim();
_.each(moviesQuoteList, function (quote) {
if (quote.text.toLowerCase().includes(inputEmotion)) {
moviesQuoteObject.quote = quote.text;
moviesQuoteObject.movie = quote.from;
return;
}
});
if (moviesQuoteObject.quote === "") {
moviesQuoteObject = getRandomQuoteWithDetails('M');
}
} else {
moviesQuoteObject = getRandomQuoteWithDetails('M');
}
return moviesQuoteObject;
},
getSeriesQuote: function (inpString) {
if (inpString) {
inputEmotion = inpString.toLowerCase().trim();
_.each(seriesQuoteList, function (quote) {
if (quote.text.toLowerCase().includes(inputEmotion)) {
matchingQuote = quote.text;
return;
}
});
} else {
matchingQuote = getRandomQuote(seriesQuoteListLength, seriesQuoteList);
}
return matchingQuote;
},
getQuoteWithSeriesName: function (inpString) {
if (inpString) {
inputEmotion = inpString.toLowerCase().trim();
_.each(seriesQuoteList, function (quote) {
if (quote.text.toLowerCase().includes(inputEmotion)) {
seriesQuoteObject.quote = quote.text;
seriesQuoteObject.series = quote.from;
return;
}
});
if (seriesQuoteObject.quote === "") {
seriesQuoteObject = getRandomQuoteWithDetails('S');
}
} else {
seriesQuoteObject = getRandomQuoteWithDetails('S');
}
return seriesQuoteObject;
},
displayQuote: function (animationType) {
if (animationType) {
getAnimationType(animationType)(getRandomQuote(genericQuoteListLength, genericQuoteList));
}
else {
chalkAnimation.rainbow(getRandomQuote(genericQuoteListLength, genericQuoteList));
}
},
displayMovieQuote: function (animationType) {
if (animationType) {
getAnimationType(animationType)(getRandomQuoteWithDetails('M').quote);
}
else {
chalkAnimation.rainbow(getRandomQuoteWithDetails('M').quote);
}
},
displaySeriesQuote: function (animationType) {
if (animationType) {
getAnimationType(animationType)(getRandomQuoteWithDetails('S').quote);
}
else {
chalkAnimation.rainbow(getRandomQuoteWithDetails('S').quote);
}
}
}
function getAnimationType(animationType) {
if (animationType == '' || animationType.toLowerCase() == 'rainbow') {
return chalkAnimation.rainbow;
}
else if (animationType.toLowerCase() == 'pulse') { return chalkAnimation.pulse }
else if (animationType.toLowerCase() == 'karaoke') { return chalkAnimation.karaoke }
else if (animationType.toLowerCase() == 'neon') { return chalkAnimation.neon }
else if (animationType.toLowerCase() == 'radar') { return chalkAnimation.radar }
else if (animationType.toLowerCase() == 'glitch') { return chalkAnimation.glitch }
else return chalkAnimation.rainbow;
}
function getRandomQuote(listLength, quoteList) {
index = randomInt(0, listLength - 1);
matchingQuote = quoteList[index].text;
return matchingQuote;
}
function getRandomQuoteWithDetails(quoteType) {
if (quoteType === 'M') {
// Movie quote
index = randomInt(0, moviesQuoteListLength - 1);
moviesQuoteObject.quote = moviesQuoteList[index].text;
moviesQuoteObject.movie = moviesQuoteList[index].from;
return moviesQuoteObject;
} else if (quoteType === 'S') {
// Series quote
index = randomInt(0, seriesQuoteListLength - 1);
seriesQuoteObject.quote = seriesQuoteList[index].text;
seriesQuoteObject.movie = seriesQuoteList[index].from;
return seriesQuoteObject;
} else {
// Generic quote
index = randomInt(0, genericQuoteListLength - 1);
genericQuoteObject.quote = genericQuoteList[index].text;
genericQuoteObject.author = genericQuoteList[index].from;
return genericQuoteObject;
}
}
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}