UNPKG

social-link-parser

Version:

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

51 lines 1.75 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 = ['cameo.com']; const subdomains = []; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); export const cameo = { id: Platforms.Cameo, name: 'Cameo', color: '#EB1C2D', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/([A-Za-z0-9_.]{3,40})/?${QUERY_HASH}$`, 'i'), handle: /^[A-Za-z0-9_.]{3,40}$/, content: { category: new RegExp(`^https?://${DOMAIN_PATTERN}/c/([A-Za-z0-9_-]{3,40})/?${QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.category?.test(url)); }, extract(url, res) { const cat = this.patterns.content?.category?.exec(url); if (cat) { res.username = cat[1]; res.metadata.isCategory = true; res.metadata.contentType = 'category'; 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://cameo.com/${username}`; }, normalizeUrl(url) { return normalize(url); }, }; //# sourceMappingURL=index.js.map