forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
internet.js
101 lines (84 loc) · 3.29 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var faker = require('../index'),
password_generator = require('../vendor/password-generator.js'),
random_ua = require('../vendor/user-agent');
var internet = {
avatar: function () {
return faker.random.array_element(faker.definitions.internet.avatar_uri);
},
email: function (firstName, lastName, provider) {
provider = provider || faker.random.array_element(faker.definitions.internet.free_email);
return faker.helpers.slugify(faker.internet.userName(firstName, lastName)) + "@" + provider;
},
userName: function (firstName, lastName) {
var result;
firstName = firstName || faker.name.firstName();
lastName = lastName || faker.name.lastName();
switch (faker.random.number(2)) {
case 0:
result = firstName + faker.random.number(99);
break;
case 1:
result = firstName + faker.random.array_element([".", "_"]) + lastName;
break;
case 2:
result = firstName + faker.random.array_element([".", "_"]) + lastName + faker.random.number(99);
break;
}
result = result.replace(/'/g, "");
result = result.replace(/ /g, "");
return result;
},
protocol: function () {
var protocols = ['http','https'];
return faker.random.array_element(protocols);
},
url: function () {
return faker.internet.protocol() + '://' + faker.internet.domainName();
},
domainName: function () {
return faker.internet.domainWord() + "." + faker.internet.domainSuffix();
},
domainSuffix: function () {
return faker.random.array_element(faker.definitions.internet.domain_suffix);
},
domainWord: function () {
return faker.name.firstName().replace(/([^A-Z0-9._%+-])/ig, '').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(".");
},
userAgent: function () {
return random_ua.generate();
},
color: function (baseRed255, baseGreen255, baseBlue255) {
baseRed255 = baseRed255 || 0;
baseGreen255 = baseGreen255 || 0;
baseBlue255 = baseBlue255 || 0;
// 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) + baseGreen255) / 2);
var blue = Math.floor((faker.random.number(256) + baseBlue255) / 2);
var redStr = red.toString(16);
var greenStr = green.toString(16);
var blueStr = blue.toString(16);
return '#' +
(redStr.length === 1 ? '0' : '') + redStr +
(greenStr.length === 1 ? '0' : '') + greenStr +
(blueStr.length === 1 ? '0': '') + blueStr;
},
password: function (len, memorable, pattern, prefix) {
len = len || 15;
if (typeof memorable === "undefined") {
memorable = false;
}
return password_generator(len, memorable, pattern, prefix);
}
};
module.exports = internet;