Skip to content

Commit

Permalink
Merge branch 'next' into 1348-mark-mersenne-module-as-internal-and-hi…
Browse files Browse the repository at this point in the history
…de-it-from-ts-and-the-api-docs
  • Loading branch information
Shinigami92 authored Oct 14, 2022
2 parents c97b0d2 + a7cd422 commit 6a724a7
Show file tree
Hide file tree
Showing 30 changed files with 84 additions and 83 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,11 @@ This rule improves the comments readability by grouping equivalent tags and maki

```ts
/**
* This is a bad JSDoc block, because it has no linebreaks between sections.
* This is a good JSDoc block, because it follows the Faker preferences.
*
* @param bar The first argument.
* @param baz The second argument.
*
* @example foo(1, 1) // [1, 1]
* @example foo(13, 56) // [13, 56]
*/
Expand All @@ -337,11 +339,9 @@ function foo(bar: number, baz: number): [number, number] {

```ts
/**
* This is a good JSDoc block, because it follows the Faker preferences.
*
* This is a bad JSDoc block, because it has no linebreaks between sections.
* @param bar The first argument.
* @param baz The second argument.
*
* @example foo(1, 1) // [1, 1]
* @example foo(13, 56) // [13, 56]
*/
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ All locales together are around 5 MB in size.
| en_GB | English (Great Britain) |
| en_GH | English (Ghana) |
| en_IE | English (Ireland) |
| en_IND | English (India) |
| en_IN | English (India) |
| en_NG | Nigeria (English) |
| en_US | English (United States) |
| en_ZA | English (South Africa) |
Expand Down
6 changes: 3 additions & 3 deletions src/locale/en_IND.ts → src/locale/en_IN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import { Faker } from '../faker';
import en from '../locales/en';
import en_IND from '../locales/en_IND';
import en_IN from '../locales/en_IN';

export const faker = new Faker({
locale: 'en_IND',
locale: 'en_IN',
localeFallback: 'en',
locales: {
en_IND,
en_IN,
en,
},
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/locales/en_IND/index.ts → src/locales/en_IN/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import internet from './internet';
import name_ from './name';
import phone_number from './phone_number';

const en_IND: LocaleDefinition = {
const en_IN: LocaleDefinition = {
title: 'English (India)',
address,
company,
Expand All @@ -18,4 +18,4 @@ const en_IND: LocaleDefinition = {
phone_number,
};

export default en_IND;
export default en_IN;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import en_CA from './en_CA';
import en_GB from './en_GB';
import en_GH from './en_GH';
import en_IE from './en_IE';
import en_IND from './en_IND';
import en_IN from './en_IN';
import en_NG from './en_NG';
import en_US from './en_US';
import en_ZA from './en_ZA';
Expand Down Expand Up @@ -79,7 +79,7 @@ export type KnownLocale =
| 'en_GB'
| 'en_GH'
| 'en_IE'
| 'en_IND'
| 'en_IN'
| 'en_NG'
| 'en_US'
| 'en_ZA'
Expand Down Expand Up @@ -140,7 +140,7 @@ const locales: KnownLocales = {
en_GB,
en_GH,
en_IE,
en_IND,
en_IN,
en_NG,
en_US,
en_ZA,
Expand Down
12 changes: 6 additions & 6 deletions src/modules/address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,20 +383,20 @@ export class AddressModule {
* @param isMetric If `true` assume the radius to be in kilometers. If `false` for miles. Defaults to `false`.
*
* @example
* faker.address.nearbyGPSCoordinate() // [ '33.8475', '-170.5953' ]
* faker.address.nearbyGPSCoordinate([33, -170]) // [ '33.0165', '-170.0636' ]
* faker.address.nearbyGPSCoordinate([33, -170], 1000, true) // [ '37.9163', '-179.2408' ]
* faker.address.nearbyGPSCoordinate() // [ 33.8475, -170.5953 ]
* faker.address.nearbyGPSCoordinate([33, -170]) // [ 33.0165, -170.0636 ]
* faker.address.nearbyGPSCoordinate([33, -170], 1000, true) // [ 37.9163, -179.2408 ]
*
* @since 5.0.0
*/
nearbyGPSCoordinate(
coordinate?: [latitude: number, longitude: number],
radius: number = 10,
isMetric: boolean = false
): [latitude: string, longitude: string] {
): [latitude: number, longitude: number] {
// If there is no coordinate, the best we can do is return a random GPS coordinate.
if (coordinate === undefined) {
return [this.latitude(), this.longitude()];
return [parseFloat(this.latitude()), parseFloat(this.longitude())];
}

const angleRadians = this.faker.datatype.float({
Expand Down Expand Up @@ -436,7 +436,7 @@ export class AddressModule {
// Box longitude [-180°, 180°]
newCoordinate[1] = (((newCoordinate[1] % 360) + 540) % 360) - 180;

return [newCoordinate[0].toFixed(4), newCoordinate[1].toFixed(4)];
return [newCoordinate[0], newCoordinate[1]];
}

/**
Expand Down
12 changes: 3 additions & 9 deletions src/modules/company/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,10 @@ export class CompanyModule {
* @since 7.4.0
*/
name(): string {
// ToDo: This `staticFormats` pattern should be removed in the future. It is only used to maintain backwards compatibility.
const staticFormats = [
'{{name.lastName}} {{company.companySuffix}}',
'{{name.lastName}} - {{name.lastName}}',
'{{name.lastName}}, {{name.lastName}} and {{name.lastName}}',
];
const formats =
this.faker.definitions.company.name_patterns ?? staticFormats;
const pattern = this.faker.helpers.arrayElement(
this.faker.definitions.company.name_patterns
);

const pattern = this.faker.helpers.arrayElement(formats);
return this.faker.helpers.fake(pattern);
}

Expand Down
6 changes: 3 additions & 3 deletions src/modules/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,16 @@ export class InternetModule {
}

/**
* Generates a random IPv4 address.
* Generates a random IPv4 or IPv6 address.
*
* @example
* faker.internet.ip() // '245.108.222.0'
* faker.internet.ip() // '4e5:f9c5:4337:abfd:9caf:1135:41ad:d8d3'
*
* @since 2.0.1
*/
ip(): string {
// TODO @Shinigami92 2022-03-21: We may want to return a IPv4 or IPv6 address here in a later major release
return this.ipv4();
return this.faker.datatype.boolean() ? this.ipv4() : this.ipv6();
}

/**
Expand Down
24 changes: 12 additions & 12 deletions test/__snapshots__/address.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ exports[`address > 42 > longitude > noArgs 1`] = `"-45.1656"`;

exports[`address > 42 > nearbyGPSCoordinate > near origin 1`] = `
[
"0.0814",
"-0.0809",
0.08140632875358443,
-0.08093642792425726,
]
`;

exports[`address > 42 > nearbyGPSCoordinate > noArgs 1`] = `
[
"-22.5828",
"106.7555",
-22.5828,
106.7555,
]
`;

Expand Down Expand Up @@ -112,15 +112,15 @@ exports[`address > 1211 > longitude > noArgs 1`] = `"154.2673"`;

exports[`address > 1211 > nearbyGPSCoordinate > near origin 1`] = `
[
"-0.0287",
"0.0596",
-0.02872051646443488,
0.05959053473372933,
]
`;

exports[`address > 1211 > nearbyGPSCoordinate > noArgs 1`] = `
[
"77.1337",
"-14.7545",
77.1337,
-14.7545,
]
`;

Expand Down Expand Up @@ -190,15 +190,15 @@ exports[`address > 1337 > longitude > noArgs 1`] = `"-85.6711"`;

exports[`address > 1337 > nearbyGPSCoordinate > near origin 1`] = `
[
"0.0806",
"-0.0061",
0.08055259537977688,
-0.006097651409731952,
]
`;

exports[`address > 1337 > nearbyGPSCoordinate > noArgs 1`] = `
[
"-42.8356",
"21.7907",
-42.8356,
21.7907,
]
`;

Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/internet.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports[`internet > 42 > httpStatusCode > noArgs 1`] = `207`;

exports[`internet > 42 > httpStatusCode > with options 1`] = `410`;

exports[`internet > 42 > ip 1`] = `"95.203.243.46"`;
exports[`internet > 42 > ip 1`] = `"cf2b:c992:7210:7d59:2ba0:0fbd:f302:f294"`;

exports[`internet > 42 > ipv4 1`] = `"95.203.243.46"`;

Expand Down Expand Up @@ -94,7 +94,7 @@ exports[`internet > 1211 > httpStatusCode > noArgs 1`] = `505`;

exports[`internet > 1211 > httpStatusCode > with options 1`] = `429`;

exports[`internet > 1211 > ip 1`] = `"237.117.228.199"`;
exports[`internet > 1211 > ip 1`] = `"117.228.199.57"`;

exports[`internet > 1211 > ipv4 1`] = `"237.117.228.199"`;

Expand Down Expand Up @@ -154,7 +154,7 @@ exports[`internet > 1337 > httpStatusCode > noArgs 1`] = `205`;

exports[`internet > 1337 > httpStatusCode > with options 1`] = `407`;

exports[`internet > 1337 > ip 1`] = `"67.143.40.54"`;
exports[`internet > 1337 > ip 1`] = `"8234:8705:3894:5f4b:41c6:1a52:bf27:dccc"`;

exports[`internet > 1337 > ipv4 1`] = `"67.143.40.54"`;

Expand Down
69 changes: 33 additions & 36 deletions test/address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,42 +300,39 @@ describe('address', () => {
describe('nearbyGPSCoordinate()', () => {
for (const isMetric of [true, false]) {
for (const radius of times(100)) {
it.each(times(5))(
`should return random gps coordinate within a distance of another one (${JSON.stringify(
{ isMetric, radius }
)}) (iter: %s)`,
() => {
const latitude1 = +faker.address.latitude();
const longitude1 = +faker.address.longitude();

const coordinate = faker.address.nearbyGPSCoordinate(
[latitude1, longitude1],
radius,
isMetric
);

expect(coordinate.length).toBe(2);
expect(coordinate[0]).toBeTypeOf('string');
expect(coordinate[1]).toBeTypeOf('string');

const latitude2 = +coordinate[0];
expect(latitude2).toBeGreaterThanOrEqual(-90.0);
expect(latitude2).toBeLessThanOrEqual(90.0);

const longitude2 = +coordinate[1];
expect(longitude2).toBeGreaterThanOrEqual(-180.0);
expect(longitude2).toBeLessThanOrEqual(180.0);

const actualDistance = haversine(
latitude1,
longitude1,
latitude2,
longitude2,
isMetric
);
expect(actualDistance).toBeLessThanOrEqual(radius);
}
);
it(`should return random gps coordinate within a distance of another one (${JSON.stringify(
{ isMetric, radius }
)})`, () => {
const latitude1 = +faker.address.latitude();
const longitude1 = +faker.address.longitude();

const coordinate = faker.address.nearbyGPSCoordinate(
[latitude1, longitude1],
radius,
isMetric
);

expect(coordinate.length).toBe(2);
expect(coordinate[0]).toBeTypeOf('number');
expect(coordinate[1]).toBeTypeOf('number');

const latitude2 = coordinate[0];
expect(latitude2).toBeGreaterThanOrEqual(-90.0);
expect(latitude2).toBeLessThanOrEqual(90.0);

const longitude2 = coordinate[1];
expect(longitude2).toBeGreaterThanOrEqual(-180.0);
expect(longitude2).toBeLessThanOrEqual(180.0);

const actualDistance = haversine(
latitude1,
longitude1,
latitude2,
longitude2,
isMetric
);
expect(actualDistance).toBeLessThanOrEqual(radius);
});
}
}
});
Expand Down
12 changes: 11 additions & 1 deletion test/internet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,19 @@ describe('internet', () => {
});

describe('ip()', () => {
it('should return a random IPv4 address with four parts', () => {
it('should return a random IPv4 or IPv6 address', () => {
const ip = faker.internet.ip();

expect(ip).toBeTruthy();
expect(ip).toBeTypeOf('string');
expect(ip).toSatisfy(validator.isIP);
});
});

describe('ipv4()', () => {
it('should return a random IPv4 with four parts', () => {
const ip = faker.internet.ipv4();

expect(ip).toBeTruthy();
expect(ip).toBeTypeOf('string');
expect(ip).toSatisfy((value: string) => validator.isIP(value, 4));
Expand Down

0 comments on commit 6a724a7

Please sign in to comment.