Skip to content

use nonNumericOnlyHash function for contentHash #15289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fit in hex digest
  • Loading branch information
vankop committed Feb 2, 2022
commit 53fcf41b3fd0dd00eaa57ef1232df8ab53c8ff75
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");
});