-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrollers.js
68 lines (57 loc) · 2.02 KB
/
controllers.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
const functions = require("./functions");
const constants = require("./constants");
const helpers = require("./helpers");
const prompt = require("prompt-sync")({ sigint: true });
const handleGenerateHashtags = allHashtags => {
const DEFAULT_NUMBER_OF_HASHTAGS = 30;
const DEFAULT_POPULARITY_RATIO = "1:1:1";
const length =
prompt(constants.STMT_NUMBER_OF_HASHTAGS) || DEFAULT_NUMBER_OF_HASHTAGS;
const popularityRatio =
prompt(constants.STMT_POPULARITY_RATIO) || DEFAULT_POPULARITY_RATIO;
functions.generateHashtags(+length, popularityRatio, allHashtags);
};
const handleAddNewHashtag = allHashtags => {
let str = "",
popularityLevel = "";
// validate hashtag's name
str = prompt(constants.STMT_ENTER_HASHTAG_NAME);
while (helpers.isHashtagInvalid(str, allHashtags)) {
console.log(helpers.isHashtagInvalid(str, allHashtags));
str = prompt(constants.STMT_ENTER_HASHTAG_NAME);
}
// validate hashtag's popularity
popularityLevel = prompt(constants.STMT_ENTER_HASHTAG_POPULARITY);
while (helpers.isPopularityInvalid(popularityLevel.toLowerCase())) {
console.log(helpers.isPopularityInvalid(popularityLevel.toLowerCase()));
popularityLevel = prompt(constants.STMT_ENTER_HASHTAG_POPULARITY);
}
// add hashtag
functions.addHashtag(
str.toLowerCase(),
popularityLevel.toLowerCase(),
allHashtags
);
};
const handleViewAllHashtags = allHashtags => {
// view all hashtags
functions.viewAllHashtags(allHashtags);
};
const handleResetHashtags = () => {
// reset the file to the initial data
functions.resetHashtags();
};
const handleExit = () => {
// exit program
functions.exitProgram();
};
const handleIncorrectInput = () => {
//incorrect input
functions.incorrectInput();
};
exports.handleGenerateHashtags = handleGenerateHashtags;
exports.handleAddNewHashtag = handleAddNewHashtag;
exports.handleViewAllHashtags = handleViewAllHashtags;
exports.handleResetHashtags = handleResetHashtags;
exports.handleExit = handleExit;
exports.handleIncorrectInput = handleIncorrectInput;