social-link-parser
Version:
Extract usernames, IDs, and metadata from social media URLs across 100+ platforms
61 lines • 2.22 kB
JavaScript
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 = ['venmo.com'];
const subdomains = [];
const DOMAIN_PATTERN = createDomainPattern(domains, subdomains);
export const venmo = {
id: Platforms.Venmo,
name: 'Venmo',
color: '#3D95CE',
domains: domains,
subdomains: subdomains,
patterns: {
profile: new RegExp(`^https?://${DOMAIN_PATTERN}/([A-Za-z0-9_\\-]{3,})/?${QUERY_HASH}$`, 'i'),
handle: /^[A-Za-z0-9_\-]{3,}$/,
content: {
qr: new RegExp(`^https?://${DOMAIN_PATTERN}/code\\?user_id=(\\d+)${QUERY_HASH}`, 'i'),
payment: new RegExp(`^https?://${DOMAIN_PATTERN}/([A-Za-z0-9_\\-]{3,})/?\\?txn=pay${QUERY_HASH}`, 'i'),
},
},
detect(url) {
if (!this.domains.some(domain => url.includes(domain)))
return false;
return this.patterns.profile.test(url) ||
!!(this.patterns.content?.qr?.test(url)) ||
!!(this.patterns.content?.payment?.test(url));
},
extract(url, res) {
const qrMatch = this.patterns.content?.qr?.exec(url);
if (qrMatch) {
res.ids.qrUserId = qrMatch[1];
res.metadata.isQr = true;
res.metadata.contentType = 'qr';
return;
}
const payMatch = this.patterns.content?.payment?.exec(url);
if (payMatch) {
res.username = payMatch[1];
res.metadata.isPayment = true;
res.metadata.contentType = 'payment';
return;
}
const profMatch = this.patterns.profile.exec(url);
if (profMatch) {
res.username = profMatch[1];
res.metadata.isProfile = true;
res.metadata.contentType = 'profile';
}
},
validateHandle(handle) {
return this.patterns.handle.test(handle.replace('@', ''));
},
buildProfileUrl(username) {
return `https://venmo.com/${username.replace('@', '')}`;
},
normalizeUrl(url) {
return normalize(url);
},
};
//# sourceMappingURL=index.js.map