Skip to content

Commit

Permalink
Merge pull request #418 from cvega/master
Browse files Browse the repository at this point in the history
[api] Added `internet.ipv6` method
  • Loading branch information
Marak authored Oct 1, 2016
2 parents 2ad5b70 + fc9d535 commit 7e96b93
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/internet.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,32 @@ var Internet = function (faker) {
"sampleResults": ["97.238.241.11"]
};

/**
* ipv6
*
* @method faker.internet.ipv6
*/
self.ipv6 = function () {
var randHash = function () {
var result = "";
for (var i = 0; i < 4; i++) {
result += (faker.random.arrayElement(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]));
}
return result
};

var result = [];
for (var i = 0; i < 8; i++) {
result[i] = randHash();
}
return result.join(":");
};

self.ipv6.schema = {
"description": "Generates a random IPv6 address.",
"sampleResults": ["2001:0db8:6276:b1a7:5213:22f1:25df:c8a0"]
};

/**
* userAgent
*
Expand Down
8 changes: 8 additions & 0 deletions test/internet.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ describe("internet.js", function () {
});
});

describe("ipv6()", function () {
it("returns a random IPv6 address with eight parts", function () {
var ip = faker.internet.ipv6();
var parts = ip.split(':');
assert.equal(parts.length, 8);
});
});

describe("userAgent()", function () {
it("returns a valid user-agent", function () {
var ua = faker.internet.userAgent();
Expand Down

0 comments on commit 7e96b93

Please sign in to comment.