From dcb6cb6a3f0e0d3b1584c15514882acb59f1f9fe Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos <102623907+pano9000@users.noreply.github.com> Date: Sun, 22 Jan 2023 20:23:46 +0100 Subject: [PATCH] refactor(isBtcAddress): get rid of unnecessary if statement and comment (#2132) * there is no need to do a check before, which RegExp use * refactored version also is bit faster as well, according to Benchmark.js tests I did --- src/lib/isBtcAddress.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/lib/isBtcAddress.js b/src/lib/isBtcAddress.js index 2dfd04651..08f12f4ca 100644 --- a/src/lib/isBtcAddress.js +++ b/src/lib/isBtcAddress.js @@ -1,14 +1,9 @@ import assertString from './util/assertString'; -// supports Bech32 addresses const bech32 = /^(bc1)[a-z0-9]{25,39}$/; const base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/; export default function isBtcAddress(str) { assertString(str); - // check for bech32 - if (str.startsWith('bc1')) { - return bech32.test(str); - } - return base58.test(str); + return bech32.test(str) || base58.test(str); }