forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress.js
100 lines (87 loc) · 3 KB
/
address.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
var Helpers = require('./helpers');
var faker = require('../index');
var definitions = require('../lib/definitions');
var address = {
zipCode: function () {
return Helpers.replaceSymbolWithNumber(faker.random.array_element(["#####", '#####-####']));
},
zipCodeFormat: function (format) {
return Helpers.replaceSymbolWithNumber(["#####", '#####-####'][format]);
},
city: function () {
var result;
switch (faker.random.number(3)) {
case 0:
result = faker.random.city_prefix() + " " + faker.random.first_name() + faker.random.city_suffix();
break;
case 1:
result = faker.random.city_prefix() + " " + faker.random.first_name();
break;
case 2:
result = faker.random.first_name() + faker.random.city_suffix();
break;
case 3:
result = faker.random.last_name() + faker.random.city_suffix();
break;
}
return result;
},
streetName: function () {
var result;
switch (faker.random.number(1)) {
case 0:
result = faker.random.last_name() + " " + faker.random.street_suffix();
break;
case 1:
result = faker.random.first_name() + " " + faker.random.street_suffix();
break;
}
return result;
},
//
// TODO: change all these methods that accept a boolean to instead accept an options hash.
//
streetAddress: function (useFullAddress) {
if (useFullAddress === undefined) { useFullAddress = false; }
var address = "";
switch (faker.random.number(2)) {
case 0:
address = Helpers.replaceSymbolWithNumber("#####") + " " + faker.Address.streetName();
break;
case 1:
address = Helpers.replaceSymbolWithNumber("####") + " " + faker.Address.streetName();
break;
case 2:
address = Helpers.replaceSymbolWithNumber("###") + " " + faker.Address.streetName();
break;
}
return useFullAddress ? (address + " " + faker.Address.secondaryAddress()) : address;
},
secondaryAddress: function () {
return Helpers.replaceSymbolWithNumber(faker.random.array_element(
[
'Apt. ###',
'Suite ###'
]
));
},
brState: function (useAbbr) {
return useAbbr ? faker.random.br_state_abbr() : faker.random.br_state();
},
ukCounty: function () {
return faker.random.uk_county();
},
ukCountry: function () {
return faker.random.uk_country();
},
usState: function (useAbbr) {
return useAbbr ? faker.random.us_state_abbr() : faker.random.us_state();
},
latitude: function () {
return (faker.random.number(180 * 10000) / 10000.0 - 90.0).toFixed(4);
},
longitude: function () {
return (faker.random.number(360 * 10000) / 10000.0 - 180.0).toFixed(4);
}
};
module.exports = address;