UNPKG

social-link-parser

Version:

Extract usernames, IDs, and metadata from social media URLs across 100+ platforms

51 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.etherscan = void 0; const types_1 = require("../../core/types"); const url_1 = require("../../utils/url"); const url_2 = require("../../utils/url"); const constants_1 = require("../../utils/constants"); const domains = ['etherscan.io']; const subdomains = []; const DOMAIN_PATTERN = (0, url_2.createDomainPattern)(domains, subdomains); exports.etherscan = { id: types_1.Platforms.Etherscan, name: 'Etherscan', color: '#21325B', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/address/(0x[0-9a-fA-F]{40})/?${constants_1.QUERY_HASH}$`, 'i'), handle: /^0x[0-9a-fA-F]{40}$/, content: { tx: new RegExp(`^https?://${DOMAIN_PATTERN}/tx/(0x[0-9a-fA-F]{64})/?${constants_1.QUERY_HASH}$`, 'i') } }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.tx?.test(url)); }, extract(url, result) { const t = this.patterns.content?.tx?.exec(url); if (t) { result.ids.txHash = t[1]; result.metadata.contentType = 'transaction'; return; } const a = this.patterns.profile.exec(url); if (a) { result.userId = a[1]; result.metadata.contentType = 'address'; } }, validateHandle(h) { return /^0x[0-9a-fA-F]{40}$/.test(h); }, buildProfileUrl(addr) { return `https://etherscan.io/address/${addr}`; }, buildContentUrl(type, id) { if (type === 'transaction' || type === 'tx') return `https://etherscan.io/tx/${id}`; return `https://etherscan.io/address/${id}`; }, normalizeUrl(url) { return (0, url_1.normalize)(url); }, }; //# sourceMappingURL=index.js.map