UNPKG

social-link-parser

Version:

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

71 lines 2.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.clubhouse = 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 = ['clubhouse.com']; const subdomains = []; const DOMAIN_PATTERN = (0, url_2.createDomainPattern)(domains, subdomains); exports.clubhouse = { id: types_1.Platforms.Clubhouse, name: 'Clubhouse', color: '#F5DF4D', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/@([A-Za-z0-9_.]{3,30})/?${constants_1.QUERY_HASH}$`, 'i'), handle: /^@?[A-Za-z0-9_.]{3,30}$/, content: { club: new RegExp(`^https?://${DOMAIN_PATTERN}/club/([A-Za-z0-9_.-]{3,50})/?${constants_1.QUERY_HASH}$`, 'i'), event: new RegExp(`^https?://${DOMAIN_PATTERN}/event/([A-Za-z0-9]{6,})/?${constants_1.QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.club?.test(url)) || !!(this.patterns.content?.event?.test(url)); }, extract(url, res) { const clubMatch = this.patterns.content?.club?.exec(url); if (clubMatch) { res.ids.clubName = clubMatch[1]; res.metadata.isClub = true; res.metadata.contentType = 'club'; return; } const eventMatch = this.patterns.content?.event?.exec(url); if (eventMatch) { res.ids.eventId = eventMatch[1]; 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://clubhouse.com/@${username.replace(/^@/, '')}`; }, buildContentUrl(contentType, id) { if (contentType === 'club') return `https://clubhouse.com/club/${id}`; if (contentType === 'event') return `https://clubhouse.com/event/${id}`; return ''; }, normalizeUrl(url) { return (0, url_1.normalize)(url); }, }; //# sourceMappingURL=index.js.map