diff options
| author | Marak <[email protected]> | 2021-03-22 13:50:18 -0400 |
|---|---|---|
| committer | Marak <[email protected]> | 2021-03-22 13:50:30 -0400 |
| commit | 6754043630bc736685683f7e2b4c4da7b4f7a924 (patch) | |
| tree | 8d21cde6b88240aa9256a036e30d7e0dd7fff2de /lib | |
| parent | f218099767a9a356738574c6d94aa8de37ce37f3 (diff) | |
| download | faker-6754043630bc736685683f7e2b4c4da7b4f7a924.tar.xz faker-6754043630bc736685683f7e2b4c4da7b4f7a924.zip | |
Fixes linting for address.js
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/address.js | 210 |
1 files changed, 105 insertions, 105 deletions
diff --git a/lib/address.js b/lib/address.js index 810424a6..bf295ba2 100644 --- a/lib/address.js +++ b/lib/address.js @@ -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 @@ -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; } // @@ -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; } /** @@ -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); } /** @@ -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); } /** @@ -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 ###' + ] + )); } /** @@ -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); @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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; } |
