Skip to content

Commit

Permalink
fit in hex digest
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Feb 2, 2022
1 parent f1d329c commit 53fcf41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/util/nonNumericOnlyHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = (hash, hashLength) => {
if (hashLength < 1) return "";
const slice = hash.slice(0, hashLength);
if (slice.match(/[^\d]/)) return slice;
return `${String.fromCharCode(A_CODE + parseInt(hash[0], 10))}${slice.slice(
1
)}`;
return `${String.fromCharCode(
A_CODE + (parseInt(hash[0], 10) % 6)
)}${slice.slice(1)}`;
};
6 changes: 5 additions & 1 deletion test/nonNumericOnlyHash.unittest.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ it("0111", () => {
});

it("911a", () => {
expect(nonNumericOnlyHash("911a", 3)).toBe("j11");
expect(nonNumericOnlyHash("911a", 3)).toBe("d11");
});

it("511a", () => {
expect(nonNumericOnlyHash("511a", 3)).toBe("f11");
});

0 comments on commit 53fcf41

Please sign in to comment.