From a0c255dc3475a5487a862409436167543c5170d9 Mon Sep 17 00:00:00 2001 From: Florent Kolosowski Date: Tue, 29 Sep 2015 18:00:16 +0200 Subject: [PATCH 1/3] add hexToRgb --- string.js | 17 +++++++++-------- string/hexToRgb.js | 8 ++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 string/hexToRgb.js diff --git a/string.js b/string.js index 8609f09..b185664 100644 --- a/string.js +++ b/string.js @@ -1,13 +1,14 @@ 'use strict'; module.exports = { - 'chunk' : require('./string/chunk'), - 'replaces' : require('./string/replaces'), - 'rot13' : require('./string/rot13'), - 'rreplaces': require('./string/rreplaces'), - 'sprintf' : require('./string/sprintf'), - 'stripEnd' : require('./string/stripEnd'), - 'crc32' : require('./string/crc32'), - 'stripStart' : require('./string/stripStart') + 'chunk' : require('./string/chunk'), + 'replaces' : require('./string/replaces'), + 'rot13' : require('./string/rot13'), + 'rreplaces' : require('./string/rreplaces'), + 'sprintf' : require('./string/sprintf'), + 'stripEnd' : require('./string/stripEnd'), + 'crc32' : require('./string/crc32'), + 'stripStart' : require('./string/stripStart'), + 'hexToRgb' : require('./string/hexToRgb') }; diff --git a/string/hexToRgb.js b/string/hexToRgb.js new file mode 100644 index 0000000..db08461 --- /dev/null +++ b/string/hexToRgb.js @@ -0,0 +1,8 @@ +"use strict"; + +var hexToRgb = function(str){ + var hex = String(str).match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/); + return (hex) ? hex.slice(1) : null; +}; + +module.exports = hexToRgb; \ No newline at end of file From ade65bc78147bb8c8fcec572e631282a9ffe2974 Mon Sep 17 00:00:00 2001 From: Florent Kolosowski Date: Wed, 30 Sep 2015 10:26:24 +0200 Subject: [PATCH 2/3] fix coverage exclusion --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1fac101..91bdc32 100755 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "url": "git@github.com:131/nyks.git" }, "scripts": { - "test": " node node_modules/istanbul/lib/cli.js cover -x child_process/* -x process/* -x crypt/* -x path/* node_modules/mocha/bin/_mocha test/" + "test": " node node_modules/istanbul/lib/cli.js cover -x 'crypt/*' -x 'path/*' -x 'child_process/*' -x 'process/*' node_modules/mocha/bin/_mocha test/" }, "readme": "# nyks toolkit\r\n\r\nExtend nodejs & javascript native API of missing functions.\r\n", "readmeFilename": "README.md", From cdd08806e856a0e252f1ba67733468eeb44e2bbe Mon Sep 17 00:00:00 2001 From: Florent Kolosowski Date: Wed, 30 Sep 2015 10:38:53 +0200 Subject: [PATCH 3/3] test hexToRgb --- test/string.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/string.js b/test/string.js index 35dfb98..f7bfbe0 100644 --- a/test/string.js +++ b/test/string.js @@ -9,6 +9,7 @@ var rot13 = require('../string/rot13') var crc32 = require('../string/crc32') var chunk = require('../string/chunk') var sprintf = require('../string/sprintf'); +var hexToRgb = require('../string/hexToRgb'); @@ -79,7 +80,6 @@ describe("strings functions", function(){ it("should test sprinf", function(){ - expect(sprintf('Hallo %s!', 'Welt')).to.be('Hallo Welt!'); }); @@ -89,4 +89,11 @@ describe("strings functions", function(){ it("should test crc32", function(){ expect(crc32("foobar")).to.be(-1628037227); }); + + it("should test hexToRgb", function() { + expect(hexToRgb('#FF0000')).to.eql(['FF', '00', '00']); + + expect(hexToRgb('not_an_hexa')).to.be(null); + }); + });