UNPKG

social-link-parser

Version:

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

48 lines 1.81 kB
import { Platforms } from '../../core/types.js'; import { normalize } from '../../utils/url.js'; import { createDomainPattern } from '../../utils/url.js'; import { QUERY_HASH } from '../../utils/constants.js'; const domains = ['etherscan.io']; const subdomains = []; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); export const etherscan = { id: Platforms.Etherscan, name: 'Etherscan', color: '#21325B', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/address/(0x[0-9a-fA-F]{40})/?${QUERY_HASH}$`, 'i'), handle: /^0x[0-9a-fA-F]{40}$/, content: { tx: new RegExp(`^https?://${DOMAIN_PATTERN}/tx/(0x[0-9a-fA-F]{64})/?${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 normalize(url); }, }; //# sourceMappingURL=index.js.map