Skip to content

Commit

Permalink
refactor(isBtcAddress): get rid of unnecessary if statement and comme…
Browse files Browse the repository at this point in the history
…nt (#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
  • Loading branch information
pano9000 authored Jan 22, 2023
1 parent 394eebf commit dcb6cb6
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/lib/isBtcAddress.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit dcb6cb6

Please sign in to comment.