Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(internet)!: ip now returns ipv4 and ipv6 #1059

Merged
merged 8 commits into from
Oct 14, 2022
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
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
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