Skip to content

Commit

Permalink
Fixes linting for address.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Mar 22, 2021
1 parent f218099 commit 6754043
Showing 1 changed file with 105 additions and 105 deletions.
210 changes: 105 additions & 105 deletions lib/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
function Address (faker) {
var f = faker.fake,
Helpers = faker.helpers;
Helpers = faker.helpers;

/**
* Generates random zipcode from format. If format is not specified, the
Expand Down Expand Up @@ -112,21 +112,21 @@ function Address (faker) {
* @method faker.address.streetName
*/
this.streetName = function () {
var result;
var suffix = faker.address.streetSuffix();
if (suffix !== "") {
suffix = " " + suffix
}
var result;
var suffix = faker.address.streetSuffix();
if (suffix !== "") {
suffix = " " + suffix
}

switch (faker.datatype.number(1)) {
switch (faker.datatype.number(1)) {
case 0:
result = faker.name.lastName() + suffix;
break;
result = faker.name.lastName() + suffix;
break;
case 1:
result = faker.name.firstName() + suffix;
break;
}
return result;
result = faker.name.firstName() + suffix;
break;
}
return result;
}

//
Expand All @@ -139,20 +139,20 @@ function Address (faker) {
* @param {Boolean} useFullAddress
*/
this.streetAddress = function (useFullAddress) {
if (useFullAddress === undefined) { useFullAddress = false; }
var address = "";
switch (faker.datatype.number(2)) {
if (useFullAddress === undefined) { useFullAddress = false; }
var address = "";
switch (faker.datatype.number(2)) {
case 0:
address = Helpers.replaceSymbolWithNumber("#####") + " " + faker.address.streetName();
break;
address = Helpers.replaceSymbolWithNumber("#####") + " " + faker.address.streetName();
break;
case 1:
address = Helpers.replaceSymbolWithNumber("####") + " " + faker.address.streetName();
break;
address = Helpers.replaceSymbolWithNumber("####") + " " + faker.address.streetName();
break;
case 2:
address = Helpers.replaceSymbolWithNumber("###") + " " + faker.address.streetName();
break;
}
return useFullAddress ? (address + " " + faker.address.secondaryAddress()) : address;
address = Helpers.replaceSymbolWithNumber("###") + " " + faker.address.streetName();
break;
}
return useFullAddress ? (address + " " + faker.address.secondaryAddress()) : address;
}

/**
Expand All @@ -161,7 +161,7 @@ function Address (faker) {
* @method faker.address.streetSuffix
*/
this.streetSuffix = function () {
return faker.random.arrayElement(faker.definitions.address.street_suffix);
return faker.random.arrayElement(faker.definitions.address.street_suffix);
}

/**
Expand All @@ -170,7 +170,7 @@ function Address (faker) {
* @method faker.address.streetPrefix
*/
this.streetPrefix = function () {
return faker.random.arrayElement(faker.definitions.address.street_prefix);
return faker.random.arrayElement(faker.definitions.address.street_prefix);
}

/**
Expand All @@ -179,12 +179,12 @@ function Address (faker) {
* @method faker.address.secondaryAddress
*/
this.secondaryAddress = function () {
return Helpers.replaceSymbolWithNumber(faker.random.arrayElement(
[
'Apt. ###',
'Suite ###'
]
));
return Helpers.replaceSymbolWithNumber(faker.random.arrayElement(
[
'Apt. ###',
'Suite ###'
]
));
}

/**
Expand Down Expand Up @@ -214,11 +214,11 @@ function Address (faker) {
this.countryCode = function (alphaCode) {

if (typeof alphaCode === 'undefined' || alphaCode === 'alpha-2') {
return faker.random.arrayElement(faker.definitions.address.country_code);
return faker.random.arrayElement(faker.definitions.address.country_code);
}

if (alphaCode === 'alpha-3') {
return faker.random.arrayElement(faker.definitions.address.country_code_alpha_3);
return faker.random.arrayElement(faker.definitions.address.country_code_alpha_3);
}

return faker.random.arrayElement(faker.definitions.address.country_code);
Expand All @@ -232,7 +232,7 @@ function Address (faker) {
* @param {Boolean} useAbbr
*/
this.state = function (useAbbr) {
return faker.random.arrayElement(faker.definitions.address.state);
return faker.random.arrayElement(faker.definitions.address.state);
}

/**
Expand All @@ -241,7 +241,7 @@ function Address (faker) {
* @method faker.address.stateAbbr
*/
this.stateAbbr = function () {
return faker.random.arrayElement(faker.definitions.address.state_abbr);
return faker.random.arrayElement(faker.definitions.address.state_abbr);
}

/**
Expand All @@ -253,15 +253,15 @@ function Address (faker) {
* @param {number} precision default is 4
*/
this.latitude = function (max, min, precision) {
max = max || 90
min = min || -90
precision = precision || 4

return faker.datatype.number({
max: max,
min: min,
precision: parseFloat((0.0).toPrecision(precision) + '1')
}).toFixed(precision);
max = max || 90
min = min || -90
precision = precision || 4

return faker.datatype.number({
max: max,
min: min,
precision: parseFloat((0.0).toPrecision(precision) + '1')
}).toFixed(precision);
}

/**
Expand All @@ -273,15 +273,15 @@ function Address (faker) {
* @param {number} precision default is 4
*/
this.longitude = function (max, min, precision) {
max = max || 180
min = min || -180
precision = precision || 4

return faker.datatype.number({
max: max,
min: min,
precision: parseFloat((0.0).toPrecision(precision) + '1')
}).toFixed(precision);
max = max || 180
min = min || -180
precision = precision || 4

return faker.datatype.number({
max: max,
min: min,
precision: parseFloat((0.0).toPrecision(precision) + '1')
}).toFixed(precision);
}

/**
Expand Down Expand Up @@ -347,64 +347,64 @@ function Address (faker) {
};

this.nearbyGPSCoordinate = function(coordinate, radius, isMetric) {
function randomFloat(min, max) {
return Math.random() * (max-min) + min;
}
function degreesToRadians(degrees) {
return degrees * (Math.PI/180.0);
}
function radiansToDegrees(radians) {
return radians * (180.0/Math.PI);
}
function kilometersToMiles(miles) {
return miles * 0.621371;
}
function coordinateWithOffset(coordinate, bearing, distance, isMetric) {
var R = 6378.137; // Radius of the Earth (http://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html)
var d = isMetric ? distance : kilometersToMiles(distance); // Distance in km

var lat1 = degreesToRadians(coordinate[0]); //Current lat point converted to radians
var lon1 = degreesToRadians(coordinate[1]); //Current long point converted to radians

var lat2 = Math.asin(Math.sin(lat1) * Math.cos(d/R) +
function randomFloat(min, max) {
return Math.random() * (max-min) + min;
}
function degreesToRadians(degrees) {
return degrees * (Math.PI/180.0);
}
function radiansToDegrees(radians) {
return radians * (180.0/Math.PI);
}
function kilometersToMiles(miles) {
return miles * 0.621371;
}
function coordinateWithOffset(coordinate, bearing, distance, isMetric) {
var R = 6378.137; // Radius of the Earth (http://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html)
var d = isMetric ? distance : kilometersToMiles(distance); // Distance in km

var lat1 = degreesToRadians(coordinate[0]); //Current lat point converted to radians
var lon1 = degreesToRadians(coordinate[1]); //Current long point converted to radians

var lat2 = Math.asin(Math.sin(lat1) * Math.cos(d/R) +
Math.cos(lat1) * Math.sin(d/R) * Math.cos(bearing));

var lon2 = lon1 + Math.atan2(
Math.sin(bearing) * Math.sin(d/R) * Math.cos(lat1),
Math.cos(d/R) - Math.sin(lat1) * Math.sin(lat2));

// Keep longitude in range [-180, 180]
if (lon2 > degreesToRadians(180)) {
lon2 = lon2 - degreesToRadians(360);
} else if (lon2 < degreesToRadians(-180)) {
lon2 = lon2 + degreesToRadians(360);
}

return [radiansToDegrees(lat2), radiansToDegrees(lon2)];
}

// If there is no coordinate, the best we can do is return a random GPS coordinate.
if (coordinate === undefined) {
return [faker.address.latitude(), faker.address.longitude()]
}
radius = radius || 10.0;
isMetric = isMetric || false;

// TODO: implement either a gaussian/uniform distribution of points in cicular region.
// Possibly include param to function that allows user to choose between distributions.

// This approach will likely result in a higher density of points near the center.
var randomCoord = coordinateWithOffset(coordinate, degreesToRadians(Math.random() * 360.0), radius, isMetric);
return [randomCoord[0].toFixed(4), randomCoord[1].toFixed(4)];
var lon2 = lon1 + Math.atan2(
Math.sin(bearing) * Math.sin(d/R) * Math.cos(lat1),
Math.cos(d/R) - Math.sin(lat1) * Math.sin(lat2));

// Keep longitude in range [-180, 180]
if (lon2 > degreesToRadians(180)) {
lon2 = lon2 - degreesToRadians(360);
} else if (lon2 < degreesToRadians(-180)) {
lon2 = lon2 + degreesToRadians(360);
}

return [radiansToDegrees(lat2), radiansToDegrees(lon2)];
}

/**
// If there is no coordinate, the best we can do is return a random GPS coordinate.
if (coordinate === undefined) {
return [faker.address.latitude(), faker.address.longitude()]
}
radius = radius || 10.0;
isMetric = isMetric || false;

// TODO: implement either a gaussian/uniform distribution of points in cicular region.
// Possibly include param to function that allows user to choose between distributions.

// This approach will likely result in a higher density of points near the center.
var randomCoord = coordinateWithOffset(coordinate, degreesToRadians(Math.random() * 360.0), radius, isMetric);
return [randomCoord[0].toFixed(4), randomCoord[1].toFixed(4)];
}

/**
* Return a random time zone
* @method faker.address.timeZone
*/
this.timeZone = function() {
return faker.random.arrayElement(faker.definitions.address.time_zone);
}
this.timeZone = function() {
return faker.random.arrayElement(faker.definitions.address.time_zone);
}

return this;
}
Expand Down

0 comments on commit 6754043

Please sign in to comment.