-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers.js
48 lines (35 loc) · 945 Bytes
/
helpers.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
'use strict';
// Dependencies
const chalk = require('chalk');
const pick = require('./pick');
const nameList = require('./data/names.json');
const tldList = require('./data/tld-list.json');
const wordList = require('./data/words.json');
function getRandomTLD() {
return pick(tldList);
}
function getRandomDomain(level = 1) {
const parts = [];
while (level--) {
parts.push(pick(wordList));
}
// Add TLD
parts.push(getRandomTLD());
return parts.join('.').toLowerCase();
}
function getRandomEmail(domain = null, emailLevel = 1, domainLevel = 1) {
const names = [];
while (emailLevel--) {
names.push(pick(nameList));
}
return `${names.join('.')}@${domain || getRandomDomain(domainLevel)}`.toLowerCase();
}
function print(data, color = 'green') {
console.log(chalk[color](data));
}
module.exports = {
getRandomDomain,
getRandomEmail,
getRandomTLD,
print,
};