social-link-parser
Version:
Extract usernames, IDs, and metadata from social media URLs across 100+ platforms
66 lines • 2.32 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 = ['paypal.me', 'paypal.com'];
const subdomains = [];
const DOMAIN_PATTERN = createDomainPattern(domains, subdomains);
export const paypal = {
id: Platforms.PayPal,
name: 'PayPal',
color: '#003087',
domains: domains,
subdomains: subdomains,
patterns: {
profile: new RegExp(`^https?://${DOMAIN_PATTERN}/(?:paypalme/)?([A-Za-z0-9]{1,20})/?${QUERY_HASH}$`, 'i'),
handle: /^[A-Za-z0-9]{1,20}$/,
content: {
payment: new RegExp(`^https?://${DOMAIN_PATTERN}/(?:paypalme/)?([A-Za-z0-9]{1,20})/(\\d+(?:\\.?\\d{1,2})?)([A-Za-z]{3})?/?${QUERY_HASH}$`, 'i'),
},
},
detect(url) {
if (!this.domains.some(domain => url.includes(domain)))
return false;
if (this.patterns.profile.test(url))
return true;
if (this.patterns.content) {
for (const pattern of Object.values(this.patterns.content)) {
if (pattern && pattern.test(url))
return true;
}
}
return false;
},
extract(url, res) {
const pay = this.patterns.content?.payment?.exec(url);
if (pay) {
res.username = pay[1];
res.ids.amount = pay[2];
if (pay[3])
res.ids.currency = pay[3];
res.metadata.isPayment = true;
res.metadata.contentType = 'payment';
return;
}
const prof = this.patterns.profile.exec(url);
if (prof) {
res.username = prof[1];
res.metadata.isProfile = true;
res.metadata.contentType = 'profile';
}
},
validateHandle(handle) {
return this.patterns.handle.test(handle);
},
buildProfileUrl(username) {
return `https://paypal.me/${username}`;
},
normalizeUrl(url) {
let normalized = normalize(url);
if (normalized.includes('paypal.com/paypalme/')) {
normalized = normalized.replace('paypal.com/paypalme/', 'paypal.me/');
}
return normalized;
},
};
//# sourceMappingURL=index.js.map