Skip to content

Commit 53fcf41

Browse files
committed
fit in hex digest
1 parent f1d329c commit 53fcf41

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/util/nonNumericOnlyHash.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = (hash, hashLength) => {
1616
if (hashLength < 1) return "";
1717
const slice = hash.slice(0, hashLength);
1818
if (slice.match(/[^\d]/)) return slice;
19-
return `${String.fromCharCode(A_CODE + parseInt(hash[0], 10))}${slice.slice(
20-
1
21-
)}`;
19+
return `${String.fromCharCode(
20+
A_CODE + (parseInt(hash[0], 10) % 6)
21+
)}${slice.slice(1)}`;
2222
};

test/nonNumericOnlyHash.unittest.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ it("0111", () => {
2323
});
2424

2525
it("911a", () => {
26-
expect(nonNumericOnlyHash("911a", 3)).toBe("j11");
26+
expect(nonNumericOnlyHash("911a", 3)).toBe("d11");
27+
});
28+
29+
it("511a", () => {
30+
expect(nonNumericOnlyHash("511a", 3)).toBe("f11");
2731
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy