social-link-parser
Version:
Extract usernames, IDs, and metadata from social media URLs across 100+ platforms
69 lines • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.paypal = 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 = ['paypal.me', 'paypal.com'];
const subdomains = [];
const DOMAIN_PATTERN = (0, url_2.createDomainPattern)(domains, subdomains);
exports.paypal = {
id: types_1.Platforms.PayPal,
name: 'PayPal',
color: '#003087',
domains: domains,
subdomains: subdomains,
patterns: {
profile: new RegExp(`^https?://${DOMAIN_PATTERN}/(?:paypalme/)?([A-Za-z0-9]{1,20})/?${constants_1.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})?/?${constants_1.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 = (0, url_1.normalize)(url);
if (normalized.includes('paypal.com/paypalme/')) {
normalized = normalized.replace('paypal.com/paypalme/', 'paypal.me/');
}
return normalized;
},
};
//# sourceMappingURL=index.js.map