UNPKG

social-link-parser

Version:

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

57 lines 1.98 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 = ['calendly.com']; const subdomains = []; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); export const calendly = { id: Platforms.Calendly, name: 'Calendly', color: '#006BFF', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/([A-Za-z0-9_.-]{3,30})/?${QUERY_HASH}$`, 'i'), handle: /^[A-Za-z0-9_.-]{3,30}$/, content: { event: new RegExp(`^https?://${DOMAIN_PATTERN}/([A-Za-z0-9_.-]{3,30})/([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?.event?.test(url)); }, extract(url, res) { const match = this.patterns.content?.event?.exec(url); if (match) { res.username = match[1]; res.ids.eventType = match[2]; res.metadata.isEvent = true; res.metadata.contentType = 'event'; 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://calendly.com/${username}`; }, buildContentUrl(contentType, type) { if (contentType === 'event') return `https://calendly.com/undefined/${type}`; return ''; }, normalizeUrl(url) { return normalize(url); }, }; //# sourceMappingURL=index.js.map