Skip to content

Commit dcb6cb6

Browse files
authored
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
1 parent 394eebf commit dcb6cb6

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

src/lib/isBtcAddress.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import assertString from './util/assertString';
22

3-
// supports Bech32 addresses
43
const bech32 = /^(bc1)[a-z0-9]{25,39}$/;
54
const base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/;
65

76
export default function isBtcAddress(str) {
87
assertString(str);
9-
// check for bech32
10-
if (str.startsWith('bc1')) {
11-
return bech32.test(str);
12-
}
13-
return base58.test(str);
8+
return bech32.test(str) || base58.test(str);
149
}

0 commit comments

Comments
 (0)