forked from qiu8310/yod-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.js
96 lines (76 loc) · 1.94 KB
/
location.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
/*
* yod-mock
* https://github.com/qiu8310/yod-mock
*
* Copyright (c) 2015 Zhonglei Qiu
* Licensed under the MIT license.
*/
module.exports = function(yod, def, _) {
yod.type('Country', def(function(abbr) {
/**
* Generate a random country in world
*
* - setting `abbr` to `true` to return the country's shorthand name
*
* _Using config `system.location.country`_
*
* @name Country
* @rule ([bool abbr = false]) -> string
*/
return _.sample(yod.config('system.location').country)[abbr ? 1 : 0];
}));
yod.type('Province & Region', def(function() {
/**
* Generate a random province in China
*
* _Using config `system.location.region`_
*
* @name Province
* @alias Region
* @rule () -> string
*/
return _.sys('location.region').split(' ').pop();
}));
yod.type('Area', def(function() {
/**
*
* Generate a random area in China
*
* _Using config `system.location.area`_
*
* @name Area
* @rule () -> string
*/
return _.sys('location.area');
}));
//yod.type('City', def(function() {}));
//yod.type('Street', def(function() {}));
yod.type('Latitude', def(function() {
/**
* Generate a random latitude float value
*
* @name Latitude
*
* @rule ([Int fixed = 5], [Int min = -90, Int max = 90]) -> Float
*/
return yod('@Float(%d, %d, "%s")', this.min, this.max, this.fixed);
}));
yod.type('Longitude', def(function() {
/**
* Generate a random longitude float value
*
* @name Longitude
* @rule ([Int fixed = 5], [Int min = -180, Int max = 180]) -> Float
*/
return yod('@Float(%d, %d, "%s")', this.min, this.max, this.fixed);
}));
yod.type('Coordinates', def(function() {
/**
* Generate a random coordinates
*
* @name Coordinates
* @rule () -> string
*/
return yod('@Latitude @Longitude');
}));
};