diff --git a/src/index.ts b/src/index.ts index 7fe6596..fc7f73f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,8 +22,15 @@ export function getPrioritizedHashAlgorithm( b: HashAlgorithm, ): PrioritizedHashAlgorithm { if (a === b) return ""; - if (!(a in supportedHashAlgorithms)) return ""; - if (!(b in supportedHashAlgorithms)) return ""; + + if (!(a in supportedHashAlgorithms)) { + return b in supportedHashAlgorithms ? b : ""; + } + + if (!(b in supportedHashAlgorithms)) { + return a in supportedHashAlgorithms ? a : ""; + } + return a < b ? b : a; } diff --git a/test/get-prioritized-hash-algorithm.js b/test/get-prioritized-hash-algorithm.js index a09e2d7..8fa4545 100644 --- a/test/get-prioritized-hash-algorithm.js +++ b/test/get-prioritized-hash-algorithm.js @@ -14,21 +14,14 @@ test("if both hash algorithms are not supported, return the empty string", funct assert.strictEqual(getPrioritizedHashAlgorithm("md5", "sha1"), ""); }); -test.todo( - "if one of the hash algorithms is unsupported, return the supported hash algorithm", - function () { - assert.strictEqual(getPrioritizedHashAlgorithm("md5", "sha256"), "sha256"); - }, -); +test("if one of the hash algorithms is unsupported, return the supported hash algorithm", function () { + assert.strictEqual(getPrioritizedHashAlgorithm("md5", "sha256"), "sha256"); +}); test("if both strings are empty, return the empty string", function () { assert.strictEqual(getPrioritizedHashAlgorithm("", ""), ""); }); -test, - todo( - "if either is an empty string, it return the supported hash algorithm", - function () { - assert.strictEqual(getPrioritizedHashAlgorithm("sha256", ""), "sha256"); - }, - ); +test("if either is an empty string, it return the supported hash algorithm", function () { + assert.strictEqual(getPrioritizedHashAlgorithm("sha256", ""), "sha256"); +});