nvmfix 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mergify.yml +10 -0
- package/.prettierrc +4 -0
- package/.travis.yml +1 -0
- package/_config.yml +1 -0
- package/config.js +1 -0
- package/data/data.json +4394 -0
- package/index.js +63 -0
- package/package.json +11 -0
package/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
let array = require("./data/data.json");
|
|
2
|
+
|
|
3
|
+
const randomNum = () => {
|
|
4
|
+
return Math.floor(Math.random() * array.length);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const getQuoteByYear = (start, end) => {
|
|
8
|
+
return array
|
|
9
|
+
.filter(i => i.year >= start && i.year <= end)
|
|
10
|
+
.sort((a, b) => (a.year > b.year ? 1 : b.year > a.year ? -1 : 0));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const getRandomQuote = () => {
|
|
14
|
+
let randNum = randomNum();
|
|
15
|
+
return array[randNum].quote;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const getSomeRandom = count => {
|
|
19
|
+
let randomQuotesArray = [];
|
|
20
|
+
let randomQuotesSet = new Set(); // to prevent duplicate quotes
|
|
21
|
+
while (randomQuotesArray.length < count) {
|
|
22
|
+
let quote = array[randomNum()];
|
|
23
|
+
if (!randomQuotesSet.has(quote)) {
|
|
24
|
+
randomQuotesArray.push(quote);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return randomQuotesArray;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getQuotesByObject = (quote, obj) => {
|
|
31
|
+
let resultArray = [];
|
|
32
|
+
quote = quote.toLowerCase();
|
|
33
|
+
object = obj;
|
|
34
|
+
array.forEach(item => {
|
|
35
|
+
item[object] = item[object].toLowerCase();
|
|
36
|
+
if (item[object] && item[object].includes(quote)) {
|
|
37
|
+
resultArray.push(item);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return resultArray;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const getQuotesByMovie = quote => {
|
|
45
|
+
return getQuotesByObject(quote, "movie");
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const getQuotesByType = quote => {
|
|
49
|
+
return getQuotesByObject(quote, "type");
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const getAll = () => {
|
|
53
|
+
return array;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
module.exports = {
|
|
57
|
+
getAll,
|
|
58
|
+
getRandomQuote,
|
|
59
|
+
getSomeRandom,
|
|
60
|
+
getQuoteByYear,
|
|
61
|
+
getQuotesByMovie,
|
|
62
|
+
getQuotesByType
|
|
63
|
+
};
|