diff options
| author | cyanos3 <[email protected]> | 2013-11-05 07:43:27 -0700 |
|---|---|---|
| committer | cyanos3 <[email protected]> | 2013-11-05 07:43:27 -0700 |
| commit | 86e3fee620f4182bd3966b2b3743cdd652d4bc0f (patch) | |
| tree | f5e32a279e428cfc5a401854e8eae54a0cd4b073 | |
| parent | 7f825fb253457f1877e3d20f252e736b903eefa2 (diff) | |
| download | faker-86e3fee620f4182bd3966b2b3743cdd652d4bc0f.tar.xz faker-86e3fee620f4182bd3966b2b3743cdd652d4bc0f.zip | |
Add random color to Internet.js
| -rw-r--r-- | lib/internet.js | 10 | ||||
| -rw-r--r-- | test/internet.unit.js | 7 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/internet.js b/lib/internet.js index 898769de..353a362a 100644 --- a/lib/internet.js +++ b/lib/internet.js @@ -37,6 +37,16 @@ var internet = { } return result.join("."); + }, + + color: function (baseRed255, baseGreen255, baseBlue255) { + + // based on awesome response : http://stackoverflow.com/questions/43044/algorithm-to-randomly-generate-an-aesthetically-pleasing-color-palette + var red = Math.floor((Faker.random.number(256) + baseRed255) / 2); + var green = Math.floor((Faker.random.number(256) + baseRed255) / 2); + var blue = Math.floor((Faker.random.number(256) + baseRed255) / 2); + + return '#' + red.toString(16) + green.toString(16) + blue.toString(16); } }; diff --git a/test/internet.unit.js b/test/internet.unit.js index d7d823cf..44879c37 100644 --- a/test/internet.unit.js +++ b/test/internet.unit.js @@ -82,4 +82,11 @@ describe("internet.js", function () { assert.equal(parts.length, 4); }); }); + + describe("color()", function () { + it("returns a valid hex value (like #ffffff)", function () { + var color = Faker.Internet.color(100, 100, 100); + assert.ok(color.match(/^#[a-f0-9]{6}$/)); + }); + }); }); |
