-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
47 lines (42 loc) · 1008 Bytes
/
utils.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
const wordsFromLocal = [
'blue lagoon',
'calm sea',
'cake',
'chocolate',
'clear blue sky',
'clouds',
'friend',
'garden',
'green forest',
'hello world',
'ice cream',
'mountain',
'peaceful sunrise',
'relaxing beach',
'summer breeze',
'sunshine',
'swimming pool',
'welcome'
];
async function getWordsFromPackage() {
try {
const { default: randomWords } = await import('random-words');
return randomWords({ exactly: 25, maxLength: 8 });
} catch (error) {
console.error('Error fetching words from package:', error);
return null;
}
}
async function wordsPromise() {
const wordsFromPackage = await getWordsFromPackage();
return wordsFromPackage?.length ? wordsFromPackage : wordsFromLocal;
}
const getRandomInt = (max) => Math.floor(Math.random() * max);
async function getRandomWord() {
const words = wordsFromLocal; // await wordsPromise();
const num = getRandomInt(words.length);
return words[num];
}
module.exports = {
getRandomWord
};