Skip to content

Commit

Permalink
chore: Allow coordinate parameter to be [string, string] (faker-js#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
samm459 authored Jun 12, 2022
1 parent 5b3f85a commit b1101d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/modules/address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,11 @@ export class Address {
* @example
* faker.address.nearbyGPSCoordinate() // [ '33.8475', '-170.5953' ]
* faker.address.nearbyGPSCoordinate([33, -170]) // [ '33.0165', '-170.0636' ]
* faker.address.nearbyGPSCoordinate([33, '-170']) // [ '33.0165', '-170.0636' ]
* faker.address.nearbyGPSCoordinate([33, -170], 1000, true) // [ '37.9163', '-179.2408' ]
*/
// TODO ST-DDT 2022-02-10: Allow coordinate parameter to be [string, string].
nearbyGPSCoordinate(
coordinate?: [latitude: number, longitude: number],
coordinate?: [latitude: number | string, longitude: number | string],
radius: number = 10,
isMetric: boolean = false
): [latitude: string, longitude: string] {
Expand Down Expand Up @@ -478,8 +478,8 @@ export class Address {
const distanceInDegree = distanceInKm / kmPerDegree; // in °

const newCoordinate: [latitude: number, longitude: number] = [
coordinate[0] + Math.sin(angleRadians) * distanceInDegree,
coordinate[1] + Math.cos(angleRadians) * distanceInDegree,
+coordinate[0] + Math.sin(angleRadians) * distanceInDegree,
+coordinate[1] + Math.cos(angleRadians) * distanceInDegree,
];

// Box latitude [-90°, 90°]
Expand Down
8 changes: 4 additions & 4 deletions test/address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ describe('address', () => {
{ isMetric, radius }
)}) (iter: %s)`,
() => {
const latitude1 = +faker.address.latitude();
const longitude1 = +faker.address.longitude();
const latitude1 = faker.address.latitude();
const longitude1 = faker.address.longitude();

const coordinate = faker.address.nearbyGPSCoordinate(
[latitude1, longitude1],
Expand All @@ -514,8 +514,8 @@ describe('address', () => {
expect(longitude2).toBeLessThanOrEqual(180.0);

const actualDistance = haversine(
latitude1,
longitude1,
+latitude1,
+longitude1,
latitude2,
longitude2,
isMetric
Expand Down

0 comments on commit b1101d9

Please sign in to comment.