-
Notifications
You must be signed in to change notification settings - Fork 1
/
german-mocker.js
117 lines (98 loc) · 2.88 KB
/
german-mocker.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
GermanMocker = function() {
var self = this;
self.sanitizeName = function(name) {
name = name.
replace(/ä/g, "ae").
replace(/ö/g, "oe").
replace(/ü/g, "ue").
replace(/Ä/g, "Ae").
replace(/Ö/g, "Oe").
replace(/Ü/g, "Ue").
replace(/ß/g, "ss").
replace(/,/g, "").
replace(/\-/g, "");
return name;
}
getRandomGenderCode = function() {
return Math.floor(Math.random());
}
self.forenames = [maleForenames, femaleForenames];
self.surnames = surnames;
self.cities = cities;
self.getRandomCity = function() {
return cities[_.random(0, cities.length)];
}
self.getRandomPhoneNumber = function(length) {
if (!length) {
length = Math.floor(Math.random() * (7 - 3 + 1)) + 3;
}
var number = "";
for (var i = 0; i < length; i++) {
var rnd = Math.floor(Math.random() * 10);
if (i === 0 && rnd === 0) {
rnd = 1;
}
number += rnd;
}
if (_.contains(["112", "110", "911", "115"], number)) {
return self.getRandomPhoneNumber(length);
}
if (length === 6 && number.substring(0, 5) === "11800") {
return self.getRandomPhoneNumber(length);
}
if (length === 6 && _.contains(["116", "118"], number.substring(0, 3))) {
return self.getRandomPhoneNumber(length);
}
return number;
}
self.getCityByName = function(name) {
return _.findWhere(cities, {
city: name
});
}
self.getRandomForename = function(gender) {
if (!gender) {
gender = getRandomGenderCode();
}
check(gender, Number);
return self.forenames[gender][_.random(0, self.forenames[gender].length)];
}
self.getRandomSurname = function() {
return surnames[_.random(0, surnames.length)];
}
self.getRandomName = function(gender) {
return self.getRandomForename(gender) + " " + self.getRandomSurname();
}
self.getRandomNameWithGender = function(gender) {
if (!gender) {
gender = getRandomGenderCode();
}
var text = ["Herr", "Frau"];
return text[gender] + " " + self.getRandomForename(gender) + " " + self.getRandomSurname();
}
self.getRandomUserName = function() {
var forename = self.sanitizeName(self.getRandomForename().toLowerCase());
var surname = self.sanitizeName(self.getRandomSurname().toLowerCase());
if (forename[1] === surname[1]) {
return forename.slice(0, 2) + surname;
}
return forename[1] + surname;
}
self.getRandomAddress = function(gender) {
if (!gender) {
gender = getRandomGenderCode();
}
var city = self.getRandomCity();
var text = ["Herr", "Frau"];
return {
gender: text[gender],
forename: self.getRandomForename(),
surname: self.getRandomSurname(),
city: city.city,
postcode: city.postcode,
prefix: city.prefix,
phone: self.getRandomPhoneNumber(Math.floor(Math.random() * (7 - 3 + 1)) + 3)
}
}
return self;
}