@azizbecha/strkit
Version:
strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.
29 lines • 1.21 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = isBtcAddress;
/**
* Validates whether a given string is a valid Bitcoin address.
*
* @param address - The string to check if it's a valid Bitcoin address.
* @returns A boolean indicating whether the string is a valid Bitcoin address.
*
* @example
* isBtcAddress("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"); // Output: true
* isBtcAddress("not-a-bitcoin-address"); // Output: false
*/
function isBtcAddress(address) {
// Regular expression to validate Bitcoin addresses (P2PKH, P2SH, and Bech32 formats)
const btcAddressRegex = /^(1|3)[a-km-zA-HJ-NP-Z1-9]{25,34}$|^(bc1)[a-zA-HJ-NP-Z0-9]{39,59}$/;
return btcAddressRegex.test(address);
}
});
//# sourceMappingURL=isBtcAddress.js.map