-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathayperos.js
More file actions
76 lines (64 loc) · 1.76 KB
/
ayperos.js
File metadata and controls
76 lines (64 loc) · 1.76 KB
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
/**
* Data-sources
*/
const subjects = require('./predictions/subjects.json');
const actions = require('./predictions/actions.json');
const endings = require('./predictions/endings.json');
const hashtags = require('./predictions/hashtags.json');
/**
* Simple 2-digits DD/MM/YY format
*/
const dateFormat = {
day: '2-digit',
month: '2-digit',
year: '2-digit'
};
/**
* Returns the current DD/MM/YY date.
* @param {String} locale. Defaults to `en-US`
*/
const getDate = (locale = 'en-US') => `${new Date(Date.now()).toLocaleDateString(locale, dateFormat)}`;
/**
* Returns the intro to the prediction
*/
const getIntro = () => `Prediction for ${getDate()}:\n\n`;
/**
* Returns a random int between min and max
* @param {number} min
* @param {number} max
*/
const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min;
/**
* Returns a random positive integer up to max
* @param {number} max
*/
const getPositiveInt = getRandomInt.bind(null, 0);
/**
* Given an array, return a random item from it
* @param {array} items
*/
const getRandomItem = (items) => items[getPositiveInt(items.length)];
/**
* Returns a random subject from the subjects json file
*/
const getSubject = () => getRandomItem(subjects);
/**
* Returns a random action from the actions json file
*/
const getAction = () => getRandomItem(actions);
/**
* Returns a random ending from the endings json file
*/
const getEnding = () => getRandomItem(endings);
/**
* Returns the hashtags for a post
*/
const getHashtags = () => `\n\n` + hashtags.join(' ');
/**
* Returns a random prediction
*/
const getPrediction = () => `${getIntro()}${getSubject()} ${getAction()} ${getEnding()} ${getHashtags()}`;
/**
* Export fn to get a prediction
*/
module.exports = getPrediction;