UNPKG

social-link-parser

Version:

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

56 lines 1.93 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 = ['buymeacoffee.com']; const subdomains = []; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); const usernamePattern = /^[A-Za-z0-9_-]{3,32}$/; export const buymeacoffee = { id: Platforms.BuyMeACoffee, name: 'BuyMeACoffee', color: '#FFDD00', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/([A-Za-z0-9_-]{3,32})/?${QUERY_HASH}$`, 'i'), handle: usernamePattern, content: { post: new RegExp(`^https?://${DOMAIN_PATTERN}/p/([A-Za-z0-9_-]+)/?${QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.post?.test(url)); }, extract(url, result) { const m = this.patterns.content?.post?.exec(url); if (m) { result.ids.postSlug = m[1]; result.metadata.contentType = 'post'; return; } const p = this.patterns.profile.exec(url); if (p) { result.username = p[1]; result.metadata.isProfile = true; result.metadata.contentType = 'profile'; } }, validateHandle(handle) { return usernamePattern.test(handle); }, buildProfileUrl(username) { return `https://buymeacoffee.com/${username}`; }, buildContentUrl(type, id) { if (type === 'post') return `https://buymeacoffee.com/p/${id}`; return `https://buymeacoffee.com/${id}`; }, normalizeUrl(url) { return normalize(url); }, }; //# sourceMappingURL=index.js.map