Skip to content

Commit

Permalink
updated isHex to check for even number of chars
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbukowski committed Nov 7, 2016
1 parent 35aa85a commit 6d415b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chainpoint-binary",
"version": "1.0.3",
"version": "1.0.4",
"description": "Tool for converting between Chainpoint JSON and binary formats",
"main": "src/chainpoint-binary.js",
"scripts": {
Expand Down
6 changes: 4 additions & 2 deletions src/rgxs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
module.exports = {
isHex: function (value) {
var hexRegex = /^[0-9A-Fa-f]{2,}$/;
return hexRegex.test(value);
var result = hexRegex.test(value);
if (result) result = value.length % 2 ? false : true;
return result;
},
isInt: function (value) {
var intRegex = /^(0|[1-9]\d*)$/;
return intRegex.test(value);
}
};
};
6 changes: 6 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,12 @@ describe("Testing Regex functions ", function () {

describe("isHex - ", function () {

it("aba false", function (done) {
var value = 'aba';
rgxs.isHex(value).should.equal(false);
done();
});

it("qweqwe123 false", function (done) {
var value = 'qweqwe123';
rgxs.isHex(value).should.equal(false);
Expand Down

0 comments on commit 6d415b5

Please sign in to comment.