forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternet.js
53 lines (42 loc) · 1.59 KB
/
internet.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
var faker = require('../index');
var internet = {
email: function () {
return faker.Helpers.slugify(faker.Internet.userName()) + "@" + faker.Helpers.slugify(faker.Internet.domainName());
},
userName: function () {
var result;
switch (faker.random.number(1)) {
case 0:
result = faker.random.first_name();
break;
case 1:
result = faker.random.first_name() + faker.random.array_element([".", "_"]) + faker.random.last_name();
break;
}
return result;
},
domainName: function () {
return faker.Internet.domainWord() + "." + faker.random.domain_suffix();
},
domainWord: function () {
return faker.random.first_name().toLowerCase();
},
ip: function () {
var randNum = function () {
return (faker.random.number(255)).toFixed(0);
};
var result = [];
for (var i = 0; i < 4; i++) {
result[i] = randNum();
}
return result.join(".");
},
color: function (baseRed255, baseGreen255, baseBlue255) {
// based on awesome response : http://stackoverflow.com/questions/43044/algorithm-to-randomly-generate-an-aesthetically-pleasing-color-palette
var red = Math.floor((faker.random.number(256) + baseRed255) / 2);
var green = Math.floor((faker.random.number(256) + baseRed255) / 2);
var blue = Math.floor((faker.random.number(256) + baseRed255) / 2);
return '#' + red.toString(16) + green.toString(16) + blue.toString(16);
}
};
module.exports = internet;