social-link-parser
Version:
Extract usernames, IDs, and metadata from social media URLs across 100+ platforms
68 lines • 2.49 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 = ['cash.app'];
const subdomains = [];
const DOMAIN_PATTERN = createDomainPattern(domains, subdomains);
export const cashapp = {
id: Platforms.CashApp,
name: 'Cash App',
color: '#00C244',
domains: domains,
subdomains: subdomains,
patterns: {
profile: new RegExp(`^https?://${DOMAIN_PATTERN}/\\$([A-Za-z][A-Za-z0-9_]{1,20})/?${QUERY_HASH}$`, 'i'),
handle: /^\$?[A-Za-z][A-Za-z0-9_]{1,20}$/,
content: {
payment: new RegExp(`^https?://${DOMAIN_PATTERN}/\\$([A-Za-z][A-Za-z0-9_]{1,20})/\\d+(?:\\.\\d{2})?/?${QUERY_HASH}$`, 'i'),
amountQuery: new RegExp(`^https?://${DOMAIN_PATTERN}/\\$([A-Za-z][A-Za-z0-9_]{1,20})/?\\?amount=(\\d+(?:\\.\\d{2})?)${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 payPath = this.patterns.content?.payment?.exec(url);
if (payPath) {
res.username = payPath[1];
res.metadata.isPayment = true;
res.metadata.contentType = 'payment';
return;
}
const payQuery = this.patterns.content?.amountQuery?.exec(url);
if (payQuery) {
res.username = payQuery[1];
res.ids.amount = payQuery[2];
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://cash.app/$${username.replace(/^\$/, '')}`;
},
normalizeUrl(url) {
return normalize(url);
},
};
//# sourceMappingURL=index.js.map